Lombok어노테이션 중 자주 사용하는 어노테이션들 정리해보겠습니다.
생성자 자동 생성
생성자를 자동 생성해주이 가능한 어노테이션들이다.
@NoArgsConstructor
- 파라미터 없는 생성자 생성
@ = NoArgsConstructor
@Getter
@Setter
public class BookSearchedEntity {
String Title;
String Author;
String PubDate;
String Description;
String Publisher;
/* 생략 가능 @NoArgsConstructor
public BooksearchedEntity(){}
*/
}
@AllArgsConstructor
- 모든 필드값으로 생성자 생성
@AllArgsConstructor
@Getter
@Setter
public class BookSearchedEntity {
String title;
String author;
/* 생략 가능 @AllArgsConstructor
public BookSearchedEntity(String title, String author){
this.title= title;
this.author = author;
}
*/
}
@RequiredArgsConstructor
- final 또는 @NonNull 선언된 필드로 생성자 생성
- @Autowired 로 설정해준 걸 해당 어노테이션으로 대체 가능
@RequiredArgsConstructor
@RestController
public class CommunicationController {
private final Logger logger = LoggerFactory.getLogger(CommunicationController.class);
//RequiredArgsConstructor
private final TemplateService templateService;
/* 생략 가능 RequiredArgsConstructor
public CommunicationController(TemplateService templateService) {
this.templateService = templateService;
}
/*
}
접근자/생성자 자동 생성
'SpringBoot' 카테고리의 다른 글
Spring Annotation 활용기 (0) | 2024.05.31 |
---|---|
@OneToOne (2) | 2024.04.22 |
페이징 개선(첫 페이지 조회결과 cache) (1) | 2024.04.18 |
OpenFeign 사용 시 헤더 값 넘기기 (0) | 2024.03.27 |
DB-> Entity, Entity->DB 자동 변환 (@Convert) (0) | 2023.05.14 |