2019.08.06

 

 로그인 ID, PW 입력창

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" 
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" 
      layout:decorate="~{layout/default}">
 
<th:block layout:fragment="customTitle">
    <title> 로그인 </title>
</th:block>
<th:block layout:fragment="customContents">
    <form action="/login" method="post"> 
    <table border = "1">
        <tr>
            <th>아이디</th>
            <td><input type="text" name="memberId"></td>
        </tr>
        <tr>
            <th>비밀번호</th>
            <td><input type="password" name="memberPw"></td>
        </tr>
        <tr style="text-align:right">
            <th colspan="2"><button type="submit"> 로그인 </button></th>
        </tr>
    </table>
    <label th:text="${result}"></label>
    </form>        
</th:block>
</html>
 
 
 Controller
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
@PostMapping("/login")
public String login(Member member, HttpSession session, Model model) {
    //입력된 아이디 비밀번호
    System.out.println(member.toString() + "<--입력된 정보");
        
    Map<String,Object> map = memberService.getMemberLogin(member);
    String result         = (Stringmap.get("result"); 
    Member loginMember     = (Member) map.get("loginMember");
        
    //로그인 실패 화면 login
    if(!result.equals("로그인 성공")) {
        model.addAttribute("result", result);
        return "/login/login";
    }
    // session 영역에 셋팅
    session.setAttribute("SID"        , loginMember.getMemberId());
    session.setAttribute("SLEVEL"    , loginMember.getMemberLevel());
    session.setAttribute("SNAME"    , loginMember.getMemberName());
 
    //로그인 성공 화면 index
    return "redirect:/";
}
 

 

 화면에 뿌려줌

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
 
    <!-- Begin Header -->
    <div id="header" th:fragment="headerFragment">
         head.html <br>
        상단 메뉴    <br><br>
        <a href="/addMember" th:if="${session.SID eq null || session.SLEVEL eq '관리자'}">01회원가입</a>
        <a href="/memberList">02회원전체검색</a>
        <a href="/addGoods" th:if="${session.SID ne null and session.SLEVEL ne '구매자'}">03상품등록</a>
        <a href="/goodsList">04상품전체검색</a>
 
        <!-- session SID가 null인 경우 로그인 링크, null이 아닌 경우 로그아웃 링크 -->
        <a th:href="@{/login}" th:if="${session.SID eq null}" style="text-align: right;">로그인</a>
        <th:block th:unless="${session.SID eq null}">
            <label>당신의 아이디 [[${session.SID}]] [[${session.SNAME}]] 님 [[${session.SLEVEL}]] 권한</label>
            <a th:href="@{/logout}" style="text-align: right;">로그아웃</a>         
        </th:block>
    </div>
    <!-- End Header -->
 
</html>
 

 

로그인 전
로그인 후

+ Recent posts