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);
}
}