본문 바로가기

개발중/Java

LOMBOK - NoArgsConstructor/AllArgsConstructor 사용

728x90
반응형

NoArgsConstructor


다영선배가 Lombok 을 쓸 때 좋은 방법을 가르쳐 줬다!
 

기존 🤨

보통 생성자는 이렇게 쓰는데

매번 번거로운 작업이 아닐 수 없다.

CategoryBasicVo vo = new CategoryBasicVo();

vo.setCategory_name(categoryName);
vo.setCategory_type(categoryType);
vo.setCategory_name_sub(categoryNameSub);
vo.setCategory_sub_use(categorySubUse);
vo.setCategory_sort_num(categorySortNum);
vo.setCategory_use(categoryUse);
vo.setCategory_public(categoryPublic);
vo.setSu_seq(suSeq);
vo.setCategoryb_p_seq(categorybPseq);

 

 

업그레이드 😄

애초에 생성할 때 데이터를 밀어 넣는 방법

CategoryBasicVo vo = CategoryBasicVo.builder()
                                    .category_name(categoryName)
                                    .category_type(categoryType)
                                    .category_name_sub(categoryNameSub)
                                    .category_sub_use(categorySubUse)
                                    .category_sort_num(categorySortNum)
                                    .category_use(categoryUse)
                                    .category_public(categoryPublic)
                                    .su_seq(suSeq)
                                    .categoryb_p_seq(categorybPseq) 
                                    .build();

생성자 세팅 (●'◡'●)

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CategoryBasicVo {
	
	private int categoryb_seq;
	private int category_sort_num;	
	private int su_seq;	
	private int categoryb_p_seq;
	
	private String category_type;
	private String category_name;
	private String category_name_sub;	
	private String category_sub_use;	
	private String category_reg_date;	
	private String category_use;	
	private String category_public;	
 
}

 

728x90
반응형