더북(TheBook)

 

4장

 

 

1분 퀴즈

1. ㉠ - ②, ㉡ - ①, ㉢ - ④, ㉣ - ③, ㉤ - ⑤

본문으로

 

 

셀프체크

1. 컨트롤러

controller/MemberController.java

(생략)
@Slf4j
@Controller
public class MemberController {
    @Autowired
    MemberRepository memberRepository;

    @GetMapping("/signup")
    public String signUpPage() {
        return "members/new";
    }

    @PostMapping("/join")
    public String join(MemberForm memberForm) {
        log.info(memberForm.toString());

 

        Member member = memberForm.toEntity();
        log.info(member.toString());

 

        Member saved = memberRepository.save(member);
        log.info(saved.toString());
        return "";
    }
}

2. DTO

dto/MemberForm.java

(생략)
@AllArgsConstructor
@ToString
public class MemberForm {
    private String email;
    private String password;
    // MemberForm 생성자와 toString() 메서드 삭제
    public Member toEntity() {
        return new Member(null, email, password);
    }
}

본문으로

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.