[개발] 회원 가입 처리 컨트롤러
필기자
2022-10-26 11:43
5,606
0
본문
kr/hull/shop/controller/MemberController.java
@RequestMapping("/members")
@Controller
@RequiredArgsConstructor
public class MemberController {
private final MemberService memberService;
private final PasswordEncoder passwordEncoder;
@GetMapping(value = "/new")
public String memberForm(Model model){
model.addAttribute("memberFormDto", new MemberFormDto());
return "member/memberForm";
}
@PostMapping(value = "/new")
public String newMember(MemberFormDto memberFormDto){
Member member = Member.createMember(memberFormDto, passwordEncoder);
memberService.saveMember(member);
//return "redirect:/";
return "main";
}
}
kr/hull/shop/controller/MainController.java
@Slf4j
@Controller
public class MainController {
@GetMapping("/")
public String index(Model model){
log.info("main 컨트롤러");
return "main";
}
}
templates/main.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layouts/layout1}">
<div layout:fragment="content">
<h1>메인페이지입니다.</h1>
</div>
</html>
실행결과 http://localhost:8080/members/new
댓글목록0