회원 가입 페이지 > 스프링 부트

본문 바로가기

[개발] 회원 가입 페이지

필기자
2022-10-26 11:38 2,650 0

본문

kr/hull/shop/controller/MemberController.java



@RequestMapping("/members")
@Controller
@RequiredArgsConstructor
public class MemberController {
    private final MemberService memberService;

    @GetMapping(value = "/new")
    public String memberForm(Model model){
        model.addAttribute("memberFormDto", new MemberFormDto());
        return "member/memberForm";
    }
}

 

templates/member/memberForm.html



<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layouts/layout1}">

    <!-- 사용자 CSS 추가 -->
    <th:block layout:fragment="css">
        <style>
            .fieldError {
                color: #bd2130;
            }
        </style>
    </th:block>

    <!-- 사용자 스크립트 추가 -->
    <th:block layout:fragment="script">

        <script th:inline="javascript">
            $(document).ready(function(){
                var errorMessage = [[${errorMessage}]];
                if(errorMessage != null){
                    alert(errorMessage);
                }
            });
        </script>

    </th:block>

    <div layout:fragment="content">

        <form action="/members/new" role="form" method="post"  th:object="${memberFormDto}">
            <div class="form-group">
                <label th:for="name">이름</label>
                <input type="text" th:field="*{name}" class="form-control" placeholder="이름을 입력해주세요">
                <p th:if="${#fields.hasErrors('name')}" th:errors="*{name}" class="fieldError">Incorrect data</p>
            </div>
            <div class="form-group">
                <label th:for="email">이메일주소</label>
                <input type="email" th:field="*{email}" class="form-control" placeholder="이메일을 입력해주세요">
                <p th:if="${#fields.hasErrors('email')}" th:errors="*{email}" class="fieldError">Incorrect data</p>
            </div>
            <div class="form-group">
                <label th:for="password">비밀번호</label>
                <input type="password" th:field="*{password}" class="form-control" placeholder="비밀번호 입력">
                <p th:if="${#fields.hasErrors('password')}" th:errors="*{password}" class="fieldError">Incorrect data</p>
            </div>
            <div class="form-group">
                <label th:for="address">주소</label>
                <input type="text" th:field="*{address}" class="form-control" placeholder="주소를 입력해주세요">
                <p th:if="${#fields.hasErrors('address')}" th:errors="*{address}" class="fieldError">Incorrect data</p>
            </div>
            <div style="text-align: center">
                <button type="submit" class="btn btn-primary" style="">Submit</button>
            </div>
            <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}">
        </form>

    </div>

</html>

 

결과 화면 http://localhost:8080/members/new

 

20221101134241_58c21c62e2e6f71b42558e4bc6ecc1e2_pzt1.png

댓글목록0

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