회원 가입 처리 컨트롤러 > 스프링 부트

본문 바로가기

[개발] 회원 가입 처리 컨트롤러

필기자
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

 

20221026114955_77e1679e6557268cbe4071a20bc8b7db_kop4.png

 

20221101134102_58c21c62e2e6f71b42558e4bc6ecc1e2_jtpb.png

 

20221026115401_77e1679e6557268cbe4071a20bc8b7db_80ig.png

20221026115453_77e1679e6557268cbe4071a20bc8b7db_75r9.png

댓글목록0

등록된 댓글이 없습니다.
게시판 전체검색