본문 바로가기
매일코딩/Spring

11.스프링 프로젝트 - 맴버 insert 상세코드

by 인생여희 2016. 11. 1.
반응형





1. 로그인/회원가입  폼

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
 
 
            
    <jsp:include page="memberHeader.jsp" flush="false"/>
 
 
    <!-- <h2 align="center">로그인 하세요</h2> -->
 
                <h1 id="community"><div>Login&Join</div></h1>
          
 
<section class="container">
            <article class="half">
                    <h1>Mana</h1>
                    <div class="tabs">
                            <span class="tab signin active"><a href="#signin">로그인</a></span>
                            <span class="tab signup"><a href="#signup">회원가입</a></span>
                    </div>
                    <div class="content">
                            <div class="signin-cont cont">
                                    <form action="${pageContext.request.contextPath}/member/login" method="post" enctype="multipart/form-data">
                                            <input type="email" name="email" id="email" class="inpt" required="required" placeholder="Your email">
                                            <label for="email">Your email</label>
                                            <input type="password" name="password" id="password" class="inpt" required="required" placeholder="Your password">
                                            <label for="password">Your password</label>
                                            <input type="checkbox" id="remember" class="checkbox" checked>
                                            <label for="remember">Remember me</label>
                                            <div class="submit-wrap">
                                                    <input type="submit" value="로그인" class="submit">
                                                    <a href="#" class="more">Forgot your password?</a>
                                            </div>
                                    </form>
                            </div>
                            <div class="signup-cont cont">
                <form action="${pageContext.request.contextPath}/member/memberInsert" method="post" enctype="multipart/form-data">
                                         
                                            <input type="text" name="name" id="name" class="inpt" required="required" placeholder="Your name">
                                            <label for="name">Your name</label>
                                                
                                                <input type="email" name="email" id="email" class="inpt" required="required" placeholder="Your email">
                                            <label for="email">Your email</label>
                                           
                                            <input type="password" name="password" id="password" class="inpt" required="required" placeholder="Your password">
                                            <label for="password">Your password</label>
                                            <div class="submit-wrap">
                                                    <input type="submit" value="가입하기" class="submit">
                                                    <a href="#" class="more">Terms and conditions</a>
                                            </div>
                                    </form>
            </div>
                    </div>
            </article>
            <div class="half bg"></div>
    </section>
 
 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script
<script type="text/javascript">
 
 
var a="${message}";
if(a.length>1){
    
    $(window).load(function() {
        alert(a);
        
    });
    
};
 
 
 
 
$('.tabs .tab').click(function(){
    if ($(this).hasClass('signin')) {
        $('.tabs .tab').removeClass('active');
        $(this).addClass('active');
        $('.cont').hide();
        $('.signin-cont').show();
    } 
    if ($(this).hasClass('signup')) {
        $('.tabs .tab').removeClass('active');
        $(this).addClass('active');
        $('.cont').hide();
        $('.signup-cont').show();
    }
});
$('.container .bg').mousemove(function(e){
    var amountMovedX = (e.pageX * -1 / 30);
    var amountMovedY = (e.pageY * -1 / 9);
    $(this).css('background-position', amountMovedX + 'px ' + amountMovedY + 'px');
});
</script>
 
 
 
    <jsp:include page="memberFooter.jsp" flush="false"/>
cs



2. 회원 가입 컨트롤러 

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
30
//controller 부분
    @RequestMapping("/member/memberInsert")
    public String memberForm(String email, String password, String name, Model model, HttpSession session) throws Exception {
        
        if (email == null) { //아이디가 입력이 안되면 다시 로그인 페이지로
 
            return "member/memberForm";
        } else {
 
            
            //로그인성공하면 1이 리턴 된다
            int result = memberDao.insertMember(email,name,password);
 
            if (result > 0) { //로그인성공하면 1이 리턴 된다.
                                
                //세션에 사용자의 정보 저장 
                session.setAttribute("userid", email);
                session.setAttribute("username", name);
                model.addAttribute("message", name+"님 가입을 축하드립니다.");
 
                return "member/login";
            } else { //로그인 실패
                model.addAttribute("message""다시 입력해 주세요");
                return "member/memberForm";
 
            }
 
        }
    }
 
cs


3.회원가입 dao



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Override
    public int insertMember(String email, String name, String password) {
        try {
 
            //마이바티스에 하나의 인자값만 전달 할 수 있다 . 그래서 map에 데이터들을 넣어서 map을 던진다.
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("email", email);
            map.put("name", name);
            map.put("password", password);
            sqlSession.insert("insertMember", map); //성공하면 1리턴 한다.
            return 1;                                                    //리턴 1 이라고 해줘도 됨..
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;                                            //오류가 발생하면 0 리턴
    }
cs



4. 회원 가입 마이바티스 




1
2
3
4
5
6
7
<insert id="insertMember">
        insert into tbl_member
        (userid,username,userpw)
        values 
        (#{email},#{name},#{password})
 
    </insert>
cs


반응형

댓글