본문 바로가기
개발의 기록/Etc..

IntelliJ Lombok 설정

by prographer J 2020. 2. 11.
728x90

컴퓨터 포맷 후 IntelliJ를 새로 설치하고 자주 까먹는 설정이라 기록을 위해서 작성합니다.

간단하지만 매번 설치할 때마다 까먹어서...ㅎㅎ

오늘도 오랜만에 포맷했는데 가물가물하니 이렇게 기록에 남깁니다.

 

 

1. File -> Settings -> Plugins -> Marketplace -> lombok  검색 -> Install

 

2. File -> Settings -> Build, Execution, Deployment-> Compiler -> Annotation Processors -> Enable annotation processing Check

 

 

추가로 제가 프로젝트하면서 많이 사용하는 Lombok 명령어입니다.

 

@Getter, @Setter : Java의 귀찮은 getter setter를 없애 코드가 간결합니다. 이 기능 때문에 처음으로 사용했었죠..

@Builder: Builder Pattern을 구현하기 위해서는 귀찮은 작업이 많은데 이 Annotation을 사용하면 쉽게 작성하게 해 줍니다.

경우에 따라서 @Geeter @Builder를 사용할 때도 있고, @Getter @Setter @Builder를 사용할 때도 있습니다.

@Data를 많이들 사용하시는데 저는 Data 사용을 지양합니다. 

왜냐하면 간편하기는 하지만 이것저것 작성해줘야 할 것들이 있어서요 ㅎㅎ

 

간단 예제,

 

1. 모델 생성

@Getter
@Setter
@Builder
public class License {
    private String id;
    private String organizationId;
    private String productName;
    private String LicenseType;
}

 

2. 모델 사용

@RestController
@RequestMapping(value = "v1/organizations/{organizationsId}/licenses")
public class LicenseController {

    @RequestMapping(value = "/{licenseId}",method = RequestMethod.GET)
    public License getLicense(@PathVariable("organizationsId") String orgId,
                              @PathVariable("licenseId") String licenseId) {

        return License.builder()
                .id(licenseId)
                .organizationId(orgId)
                .productName("Teleco")
                .LicenseType("Seat").build();

    }
}

 

 

감사합니다.

728x90

댓글