0. DB에 연동할 memberVO 객체 만들기
( 앞서 만들었지만 혹시몰라 추가해드렸어요 ~ )
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
|
public class MemberVo {
private int member_idx;
private String member_id;
private String member_name;
private String member_pw;
private String member_phone;
private Date member_regdate;
private int member_grade;
private String member_delyn;
private Date member_deldate;
public int getMember_idx() {
return member_idx;
}
public void setMember_idx(int member_idx) {
this.member_idx = member_idx;
}
public String getMember_id() {
return member_id;
}
public void setMember_id(String member_id) {
this.member_id = member_id;
}
public String getMember_name() {
return member_name;
}
public void setMember_name(String member_name) {
this.member_name = member_name;
}
public String getMember_pw() {
return member_pw;
}
public void setMember_pw(String member_pw) {
this.member_pw = member_pw;
}
public String getMember_phone() {
return member_phone;
}
public void setMember_phone(String member_phone) {
this.member_phone = member_phone;
}
public Date getMember_regdate() {
return member_regdate;
}
public void setMember_regdate(Date member_regdate) {
this.member_regdate = member_regdate;
}
public int getMember_grade() {
return member_grade;
}
public void setMember_grade(int member_grade) {
this.member_grade = member_grade;
}
public String getMember_delyn() {
return member_delyn;
}
public void setMember_delyn(String member_delyn) {
this.member_delyn = member_delyn;
}
public Date getMember_deldate() {
return member_deldate;
}
public void setMember_deldate(Date member_deldate) {
this.member_deldate = member_deldate;
}
|
cs |
1. 첫번째로 JSP 페이지 만들기 ( 간단하게 만들어볼게요~)
1
2
3
4
5
6
|
<form name="loginForm" action="/spring/loginProcess.do" method="post">
<input type="email" name="member_id" value="" maxlength="80" placeholder="아이디(이메일)" /><br/>
<input type="password" name="member_pw" value="" maxlength="20" placeholder="비밀번호"><br/>
<input type="submit" value="로그인">
<input type="reset" value="취소">
</form>
|
cs |
2. JSP 에서 전송된 데이터가 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
25
26
27
28
29
|
@PostMapping("/loginProcess.do")
public String loginProcess(@RequestParam("member_id") String member_id,
@RequestParam("member_pw") String member_pw,
HttpServletRequest request) {
HashMap<String, String> loginInfo =memberService.login(loginInfo);
// member_id 와 member_pw 를 map 에 담아서 한객체로 담아가기위함
loginInfo.put("member_id", member_id);
loginInfo.put("member_pw", member_pw);
String viewPage = null;
if(member_auth==1) { // 정상적으로 로그인되면
HttpSession session = request.getSession();
session.setAttribute("member_id", loginInfo.get("member_id"));
session.setAttribute("member_grade", loginInfo.get("member_grade"));
viewPage = "redirect:/home.do";
}else{ // 로그인 실패시 다시
viewPage = "member/login";
}
return viewPage;
}
|
cs |
3. Controller 에서 service dao 이동
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
Service
public HashMap<String, Long> login(MemberVo memberVo) {
return memberDao.loginMember(memberVo); }
Dao
public HashMap<String, Long> loginMember(HashMap<String, String> loginInfo) {
HashMap<String, Long> resultMap = sqlSession.selectOne(MAPPER+".loginMember", loginInfo);
if(resultMap.get("member_auth")== 0) {
resultMap.put("member_grade", 0L);
}
return resultMap;
}
|
cs |
4. mapper sql문실행 !!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<mapper namespace = "ezen.dev.spring.member">
<insert id="joinMember" parameterType="memberVo">
insert into member(member_id, member_pw, member_name, member_phone)
values(#{member_id}, #{member_pw}, #{member_name}, #{member_phone})
</insert>
<!-- <select id="loginMember" parameterType="memberVo" resultType="map">
select count(*) as member_auth,member_grade from member where member_id=#{member_id} and member_pw=#{member_pw}
</select> -->
<select id="loginMember" parameterType="map" resultType="map">
select count(*) as member_auth,member_grade from member where member_id=#{member_id} and member_pw=#{member_pw}
</select>
|
cs |
5. 정상적으로 되면 로그인 까지 완료 !!
감사합니다 !!
'기존 > 🏀Spring' 카테고리의 다른 글
[스프링 -4]Spring 파일 업로드 하기 (fileupload) (0) | 2022.07.14 |
---|---|
[스프링 -3]Spring 중복확인 Ajax요청 (아이디 중복확인) (0) | 2022.07.14 |
[스프링 -1]Spring 회원가입하기 (DB저장,mapper,mybatis) (0) | 2022.07.14 |
[스프링]Spring 카카오 로그인하기 , DB저장 (0) | 2022.07.14 |
(스프링) 일반배송 만들기 주문상태현황,배송중,배송대기,결제완료 (0) | 2022.07.11 |