본문 바로가기

공부/Spring

스프링 부트 3 백엔드 개발자 되기_24

어제 안됐던 AddArticleRequest 클래스 toEntity 부분 Article 클래스에서 뭐 잘못작성한거 같아서 보니까

Article에 @Builder를 두개 쓰고 있길래 하나 지웠더니 잘 적용이 됨  

 



Article클래스에 
################Article클래스에 작성한 두개###################
@Builder 
public Article(String title, String content) {
    this.title = title;
    this.content = content;
}



@Builder
public Article(String author, String title, String content){
    this.author = author;
    this.title = title;
    this.content = content;
}
###########################################################



@Builder 어노테이션 특정안한 채로 두개 써서 그런듯?

@Builder 
public Article(String title, String content) {
    this.title = title;
    this.content = content;
}
이 코드 삭제 했더니 AddArticleRequest에서 author부분 에러가 사라졌다.

public Article toEntity(String author){ //생성자를 사용해 객체 생성
        return Article.builder()
                .title(title)
                .content(content)
                .author(author)  //에러 사라짐
                .build();
    }




찾아보니까

https://theheydaze.tistory.com/194

 

01. Library - Lombok [미완성]

OS Windows 10 Home 64bit 버전 1903 (OS 빌드 18362.836) Edit Tool IntelliJ IDEA 2019.1.3 FrameWork SpringBoot 2.3.1.RELEASE Build Tool Gradle # 의존성 1 2 3 4 // Lombok compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lom

theheydaze.tistory.com

@Builder가 여러개인경우 builderClassName을 사용하지 않는 경우 내부 클래스가 서로 공유돼서 1개의@Builder만 적용된다고 함
=>2개 이상의 생성자에 @Builder를 사용할 땐 builderClassName이랑 builderMethodName을 같이사용해야함

 

 

 

 

 

다음 290pg 8단계부터하기