캐모마일 공통 코드 가이드
개요
사이트에서 사용되는 공통코드들을 사용하기 위한 기능을 제공한다.
관련 클래스
- CommonCode: 대분류/중분류/소분류에 해당하는 공통코드 목록을 조회할 수 있는 기능을 제공하는 클래스이다.
 - MainCommonCodeVO: 공통코드 대분류 관련 VO 도메인 객체이다.
 - MiddleCommonCodeVO: 공통코드 중분류 관련 VO 도메인 객체이다.
 - SubCommonCodeVO: 공통코드 소분류 관련 VO 도메인 객체이다.
 
dependency
<dependency>
  <groupId>net.lotte.chamomile.module</groupId>
  <artifactId>chamomile-commoncode</artifactId>
</dependency>
사용법
[설정]
자동으로 구성된 bean이 아닌,
직접 bean을 생성하고 싶다면 다음과 같이 생성하면 된다.
@Configuration
public class ChamomileCommonCodeConfiguration {
    @PersistenceContext
    private EntityManager em;
    @Bean
    public CommonRepository commonRepository() {
        return new CommonRepository(em);
    }
    @Bean
    public CommonCode commonCode(CommonRepository commonRepository) {
        return new CommonCode(em, commonRepository);
    }
}
[메소드]
// 대분류 기준으로 페이징 처리된 중분류 목록을 조회
List<CodeVO> listCode = commonCode.listCodes("[대분류코드]", Pageable pageable);
// 중분류 기준으로 페이징 처리된 소분류 목록을 조회
List<CodeVO> listCode = commonCode.listCodes("[대분류코드]", "[중분류코드]", Pageable pageable);
// 공통코드 문자열을 파라미터로 넘길 시 이에 해당하는 공통코드 값을 조회
String findValue = commonCode.findValue("[코드 문자열]");
// 공통코드 문자열을 파라미터로 넘길 시 이에 해당하는 공통코드 데이터를 VO 객체로 리턴
CommonCodeVO findCommonCodeVO = commonCode.find("[코드 문자열]");
// 공통코드 문자열과 페이징 파라미터를 넘길 시 이에 해당하는 공통코드 목록을 페이징 처리하여 조회
Page<Object> findPagingList = commonCode.findList("[코드 문자열]", PageRequest.of(0, 10));
// 공통코드 문자열을 넘길 시 이에 해당하는 공통코드 목록을 페이징 처리하여 조회
List<Object> newFindList = commonCode.findList("[코드 문자열]");
findValue, find, findList 에 해당하는 메소드의 String 파라미터 형태는 다양할 수 있다. 2, 3번에 해당하는 형태를 파라미터로 넘기고자 할 때에는 "." 을 사용해야 한다.
1) <"대분류ID"> 형태
- 대분류(카테고리) 공통코드 데이터를 조회
2) <"대분류ID.중분류ID"> 형태
 - 중분류 공통코드 데이터를 조회
3) <"대분류ID.중분류ID.소분류ID"> 형태
- 소분류 공통코드 데이터를 조회
 
 
[예제]
@RequiredArgsConstructor
@RestController
public class TestCommonCodeController {
    private final CommonCode commonCode;
    @GetMapping("/common-code")
    public void commonCode() throws SQLException {
        // 대분류 기준으로 중분류 목록을 조회
        Page<Object> findList = commonCode.listCodes("category00030"
                                , PageRequest.of(0, 10));
        // 중분류 기준으로 소분류 목록을 조회
        Page<Object> findSubList = commonCode.listCodes("category00030", "code00001"
                                , PageRequest.of(0, 10));
        /* 단일 공통코드 값 조회 */
        // 대분류 공통코드 값 조회
        String findCommonCodeValue = commonCode.findValue("cate1");
        // 중분류 공통코드 값 조회
        String findCommonCodeValue = commonCode.findValue("cate1.code2");
        // 소분류 공통코드 값 조회
        String findCommonCodeValue = commonCode.findValue("cate1.code1.item1");
        /* 단일 공통코드 데이터 VO 조회 */
        // 대분류 공통코드 데이터 조회
        CommonCodeVO findCommonCodeVO = commonCode.find("cate2");
        // 중분류 공통코드 데이터 조회
        CommonCodeVO findCommonCodeVO = commonCode.find("cate2.code2");
        // 소분류 공통코드 데이터 조회
        CommonCodeVO findCommonCodeVO = commonCode.find("cate2.code2.item2");
        /* 공통코드 목록 조회 */
        // 공통코드 대분류 목록 조회
        Page<Object> findPagingList = commonCode.findList("cate1", PageRequest.of(0, 10));
        List<Object> newFindList = commonCode.findList("cate1");
        // 공통코드 중분류 목록 조회
        Page<Object> findPagingList = commonCode.findList("cate1.code1"
                                    , PageRequest.of(0, 10));
        List<Object> newFindList = commonCode.findList("cate1.code1");
        // 공통코드 소분류 목록 조회
        Page<Object> findPagingList = commonCode.findList("cate1.code1.item1"
                                    , PageRequest.of(0, 10));
        List<Object> newFindList = commonCode.findList("cate1.code1.item1");
    }
}