hyeonga_code

reProject_18_Spring Scheduler 이용해서 만료된 쿠키에 적용하기 구현 준비 본문

Project_WEATHERWEAR

reProject_18_Spring Scheduler 이용해서 만료된 쿠키에 적용하기 구현 준비

hyeonga 2024. 1. 5. 06:59
반응형

 

 

reProject_17_쇼핑몰 상품 재고 반영, 장바구니 수량 변경 적용 구현

reProject_16_ 장바구니 기능 구현 수정, 재고 수량 적용 reProject_15_주문 페이지, 주문 상세 페이지 작업 2024-01-02 주문페이지로 이동 시 session이 없는 경우(로그인하지 않은 경우) , cookie 값이 없는 경

hyeonga493.tistory.com

 

2024.01.04

비회원의 경우 쿠키를 사용하여 작업하게 된다. 쿠키 만료일을 2일로 설정하여 매일 자정에 만료일이 이전인 쿠키 정보를 모두 삭제하려 한다. 이 기능을 구현하기 전에 장바구니에 쿠키를 사용해서 데이터를 넣은 후 로그인하는 경우 쿠키 아이디를 제거하고 회원 아이디를 저장하는 기능을 먼저 구현해야 엉뚱한 데이터가 삭제되는 것을 방지할 수 있다.

 

1. ClientPostController.java 수정

/** 로그인 */
	@PostMapping("clientLogin.do")
	public String clientLogin(HttpServletRequest request, HttpServletResponse response) {
		System.out.println("1. [ Client Post Controller ] clientLogin");
		
		HttpSession session = request.getSession(false);
		
		String id = request.getParameter("clientId");
		String pwd = request.getParameter("clientPwd");
		System.out.println("id : " + id + ", pwd : " + pwd);
		
		ClientVO result = clientService.getClient(id);
		
		if(result != null) {
			System.out.println("4. [ Controller ] 아이디 존재");
			
			if(pwden.matches(pwd, result.getClientPwd())) {
				System.out.println("5. [ Controller ] 비밀번호 일치");
				
				session.setAttribute("session", id);
				System.out.println("6. [ Controller ] 세션 설정");
				
				/** 세션 값 확인 방법
				 * session.getAttribute("session");
				 * session.getValue("session");
				 */

				// 쿠키 존재하는 경우 쿠키 삭제
				if(ClientCookie.checkCookie(request, response) == 1) {
					clientService.changeCookieSetId(WebUtils.getCookie(request, "clientCookie").getValue(), id);
					ClientCookie.removeCookie(WebUtils.getCookie(request, "clientCookie"), response);
				}
				
				// 최근 로그인 날짜 변경
				clientService.setLogDate(id);
				
				return "redirect:/clientMain.do";
			}
			System.out.println("5. [ Controller ] 비밀번호 불일치");
		} else {
			System.out.println("4. [ Controller ] 아이디 없음");
		}
		return "redirect:/clientLogin.do";
	}
    
    
	/** 주문 로그인 */
	@PostMapping("clientOrderLogin.do")
	public void clientOrderLogin(@RequestBody Map<String, String> data, HttpServletResponse response, HttpServletRequest request) throws IOException {
		System.out.println("1. [ Client Post Controller ] clientLogin");
		
		HttpSession session = request.getSession(false);
		
		String id = data.get("clientId");
		String pwd = data.get("clientPwd");
		
		ClientVO result = clientService.getClient(id);
		
		if(result != null) {
			response.setContentType("application/json");
			System.out.println("4. [ Controller ] 아이디 존재");
			
			if(pwden.matches(pwd, result.getClientPwd())) {
				System.out.println("5. [ Controller ] 비밀번호 일치");
				
				session.setAttribute("session", id);
				System.out.println("6. [ Controller ] 세션 설정");
				
				/** 세션 값 확인 방법
				 * session.getAttribute("session");
				 * session.getValue("session");
				 */

				// 쿠키 존재하는 경우 쿠키 삭제
				if(ClientCookie.checkCookie(request, response) == 1) {
					clientService.changeCookieSetId(WebUtils.getCookie(request, "clientCookie").getValue(), id);
					ClientCookie.removeCookie(WebUtils.getCookie(request, "clientCookie"), response);
				}
				
				response.getWriter().write(String.valueOf(1));
				
				// 최근 로그인 날짜 변경
				clientService.setLogDate(id);
				return;
			}
			response.getWriter().write(String.valueOf(2));
			System.out.println("5. [ Controller ] 비밀번호 불일치");
		} else {
			response.getWriter().write(String.valueOf(3));
			System.out.println("4. [ 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package com.w2.client.controller;
 
import java.io.IOException;
import java.util.Map;
 
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.util.WebUtils;
 
import com.w2.client.ClientService;
import com.w2.client.ClientVO;
import com.w2.util.ClientCookie;
import com.w2.util.RandomString;
 
@Controller
public class ClientPostController {
    
    @Autowired
    private ClientService clientService;
    
    @Autowired // 비밀번호 암호화
    private BCryptPasswordEncoder pwden;
    
    /** 로그인 */
    @PostMapping("clientLogin.do")
    public String clientLogin(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("1. [ Client Post Controller ] clientLogin");
        
        HttpSession session = request.getSession(false);
        
        String id = request.getParameter("clientId");
        String pwd = request.getParameter("clientPwd");
        System.out.println("id : " + id + ", pwd : " + pwd);
        
        ClientVO result = clientService.getClient(id);
        
        if(result != null) {
            System.out.println("4. [ Controller ] 아이디 존재");
            
            if(pwden.matches(pwd, result.getClientPwd())) {
                System.out.println("5. [ Controller ] 비밀번호 일치");
                
                session.setAttribute("session", id);
                System.out.println("6. [ Controller ] 세션 설정");
                
                /** 세션 값 확인 방법
                 * session.getAttribute("session");
                 * session.getValue("session");
                 */
 
                // 쿠키 존재하는 경우 쿠키 삭제
                if(ClientCookie.checkCookie(request, response) == 1) {
                    clientService.changeCookieSetId(WebUtils.getCookie(request, "clientCookie").getValue(), id);
                    ClientCookie.removeCookie(WebUtils.getCookie(request, "clientCookie"), response);
                }
                
                // 최근 로그인 날짜 변경
                clientService.setLogDate(id);
                
                return "redirect:/clientMain.do";
            }
            System.out.println("5. [ Controller ] 비밀번호 불일치");
        } else {
            System.out.println("4. [ Controller ] 아이디 없음");
        }
        return "redirect:/clientLogin.do";
    }
    
    /** 아이디 찾기 */
    @PostMapping("clientFindId.do")
    public void clientFindId(@RequestBody Map<StringString> data, HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("1. [ Client Post Controller ] clientFindId");
        
        String type = request.getParameter("type");
        String clientName = data.get("clientName");
        String keyword = data.get("keyword");
        
        String id = clientService.clientFindId(type, clientName, keyword);
        System.out.println("4. [ Controller ] 결과 : " + id);
        
        response.setContentType("application/json");
        response.getWriter().write(String.valueOf(id));
    }
    
    /** 비밀번호 찾기 */
    @PostMapping("clientFindPwd.do")
    public void clientFindPwd(@RequestBody Map<StringString> data, HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("1. [ Client Post Controller ] clientFindPwd");
        
        String type = request.getParameter("type");
        String clientName = data.get("clientName");
        String clientId = data.get("clientId");
        String keyword = data.get("keyword");
        
        int result = clientService.clientFindPwd(type, clientName, clientId, keyword);
        System.out.println("4. [ Controller ] 결과 : " + result);
        
        response.setContentType("application/json");
        response.getWriter().write(String.valueOf(result));
    }
    
    /** 비밀번호 변경 */
    @PostMapping("clientSetPwd.do")
    public void clientSetPwd(@RequestBody Map<StringString> data, HttpServletResponse response, ClientVO client) throws Exception {
        System.out.println("1. [ Client Post Controller ] clientSetPwd");
        
        client.setClientId(data.get("clientId"));
        client.setClientPwd(pwden.encode(data.get("clientPwd")));
        
        int result = clientService.clientSetPwd(client);
        System.out.println("4. [ Controller ] 결과 : " + result);
        
        response.setContentType("aaplication/json");
        response.getWriter().write(String.valueOf(result));
    }
    
    /** 중복 체크 */
    @PostMapping("clientCheck.do")
    public void clientCheck(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("1. [ Client Post Controller ] clientCheck");
        
        String comp = request.getParameter("comp");
        String with = request.getParameter("checkWith");
        
        System.err.println("comp : " + comp + ", with : " + with);
        
        int check = clientService.clientCheckService(comp, with);
        
        System.out.println("5. [ Controller ] 결과 : " + check);
        
        response.setContentType("application/json");
        response.getWriter().write(String.valueOf(check));
    }
    
    /** 회원 가입 */
    @PostMapping("clientSignup.do")
    public String clientSignup(HttpServletRequest request, ClientVO client, Model model) {
        System.out.println("1. [ Client Post Controller ] clientSignup");
        System.out.println("EmailCheck : " + request.getParameter("clientEmailCheck"));
        
        // 신규 회원 기본 설정
        client.setGradeId("S");
        client.setClientPoint(3000);
        
        if(request.getParameter("clientEmailCheck"!= null) {
            client.setClientEmailCheck("Y");
        } else {
            client.setClientEmailCheck("N");
        }
        
        // 비밀번호 암호화
        client.setClientPwd(pwden.encode(client.getClientPwd()));
        
        int result = clientService.clientSignup(client);
        model.addAttribute("result", result);
        
        if(result == 1 ) {
            System.out.println("4. [ Controller ] 가입 성공");
            return "client_login";
        }
        
        System.out.println("4. [ Controller ] 가입 실패");
        return "client_signup";
    }    
 
    /** 주문 로그인 */
    @PostMapping("clientOrderLogin.do")
    public void clientOrderLogin(@RequestBody Map<StringString> data, HttpServletResponse response, HttpServletRequest request) throws IOException {
        System.out.println("1. [ Client Post Controller ] clientLogin");
        
        HttpSession session = request.getSession(false);
        
        String id = data.get("clientId");
        String pwd = data.get("clientPwd");
        
        ClientVO result = clientService.getClient(id);
        
        if(result != null) {
            response.setContentType("application/json");
            System.out.println("4. [ Controller ] 아이디 존재");
            
            if(pwden.matches(pwd, result.getClientPwd())) {
                System.out.println("5. [ Controller ] 비밀번호 일치");
                
                session.setAttribute("session", id);
                System.out.println("6. [ Controller ] 세션 설정");
                
                /** 세션 값 확인 방법
                 * session.getAttribute("session");
                 * session.getValue("session");
                 */
 
                // 쿠키 존재하는 경우 쿠키 삭제
                if(ClientCookie.checkCookie(request, response) == 1) {
                    clientService.changeCookieSetId(WebUtils.getCookie(request, "clientCookie").getValue(), id);
                    ClientCookie.removeCookie(WebUtils.getCookie(request, "clientCookie"), response);
                }
                
                response.getWriter().write(String.valueOf(1));
                
                // 최근 로그인 날짜 변경
                clientService.setLogDate(id);
                return;
            }
            response.getWriter().write(String.valueOf(2));
            System.out.println("5. [ Controller ] 비밀번호 불일치");
        } else {
            response.getWriter().write(String.valueOf(3));
            System.out.println("4. [ Controller ] 아이디 없음");
        }
    }
    
    /** 장바구니에 상품 추가 */
    @RequestMapping("clientOrderCookie.do")
    public void clientOrderCookie(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("1. [ Client Post Controller ] clientOrderCookie");
        
        String ckId = ClientCookie.setCookie(request, response);
        
        response.setContentType("application/json");
        response.getWriter().write(String.valueOf(ckId));
        return;
    }
    
    
}

 

 

2. ClientService.java 인터페이스 수정

	// 쿠키해제(회원)
	public void changeCookieSetId(String ckId, String clientId);
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
package com.w2.client;
 
import java.util.HashMap;
import java.util.List;
 
import javax.servlet.http.Cookie;
 
public interface ClientService {
    
    // 중복 체크(아이디, 닉네임)
    public int clientCheckService(String comp, String with);
 
    // 회원 가입
    public int clientSignup(ClientVO client);
 
    // 회원정보 가져오기
    public ClientVO getClient(String id);
 
    // 최근 로그인 일자 저장
    public void setLogDate(String id);
 
    // 아이디 찾기
    public String clientFindId(String type, String clientName, String keyword);
 
    // 비밀번호 찾기
    public int clientFindPwd(String type, String clientName, String clientId, String keyword);
 
    // 비밀번호 변경
    public int clientSetPwd(ClientVO client);
 
    // 마이페이지 기본 정보
    public HashMap<String, Object> clientSetMypage(String clientId);
 
    // 쿠키해제(회원)
    public void changeCookieSetId(String ckId, String clientId);
    
}
 

 

 

 

3. ClientServiceImpl.java 클래스 수정

	// 쿠키해제(회원)
	@Override
	public void changeCookieSetId(String ckId, String clientId) {
		System.out.println("2. [ Impl ] : changeCookieSetId");
		
		clientdao.changeCookieSetId(ckId, clientId);
	}
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package com.w2.client.impl;
 
import java.util.HashMap;
 
import javax.servlet.http.Cookie;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.w2.client.ClientDAO;
import com.w2.client.ClientService;
import com.w2.client.ClientVO;
 
@Service("clientService")
public class ClientServiceImpl implements ClientService {
 
    @Autowired
    private ClientDAO clientdao;
 
    // 중복 체크(아이디, 닉네임)
    @Override
    public int clientCheckService(String comp, String with) {
        System.out.println("2. [ Impl ] : clientCheckService : " + comp + " with : " + with);
        
        HashMap<StringString> check = new HashMap<StringString>();
        check.put("comp", comp);
        check.put("with", with);
    
        int result = clientdao.clientCheck(check);
        
        if (result == 1) {
            System.out.println("4. >> clientCheck 중복 : " + result);
        } else {
            System.out.println("4. >> clientCheck 가능 : " + result);
        }
        return result;
    }
 
    // 회원 가입
    @Override
    public int clientSignup(ClientVO client) {
        System.out.println("2. [ Impl ] : clientSignup : " + client.toString());
        
        return clientdao.clientSignup(client);
        
        // 약관 동의
        
    }
 
    // 회원 정보 가져오기
    @Override
    public ClientVO getClient(String id) {
        System.out.println("2. [ Impl ] : getClient : id : " + id);
 
        return clientdao.getClient(id);
    }
 
    // 최근 로그인 일자 저장
    @Override
    public void setLogDate(String id) {
        System.out.println("7. [ Impl ] : setLogDate");
        clientdao.setLogDate(id);
    }
 
    // 아이디 찾기
    @Override
    public String clientFindId(String type, String clientName, String keyword) {
        System.out.println("2. [ Impl ] : clientFindId");
        
        HashMap<StringString> info = new HashMap<StringString>();
        info.put("type", type);
        info.put("clientName", clientName);
        info.put("keyword", keyword);
        
        return clientdao.clientFindId(info);
    }
 
    // 비밀번호 찾기
    @Override
    public int clientFindPwd(String type, String clientName, String clientId, String keyword) {
        System.out.println("2. [ Impl ] : clientFindPwd");
        
        HashMap<StringString> info = new HashMap<StringString>();
        info.put("type", type);
        info.put("clientName", clientName);
        info.put("clientId", clientId);
        info.put("keyword", keyword);
        
        return clientdao.clientFindPwd(info);
    }
 
    // 비밀번호 변경
    @Override
    public int clientSetPwd(ClientVO client) {
        System.out.println("2. [ Impl ] : clientSetPwd");
        
        return clientdao.clientSetPwd(client);
    }
 
    // 마이페이지 기본 정보
    @Override
    public HashMap<String, Object> clientSetMypage(String clientId) {
        System.out.println("2. [ Impl ] : clientSetMypage");
        
        return clientdao.clientSetMypage(clientId);
    }
 
    // 쿠키해제(회원)
    @Override
    public void changeCookieSetId(String ckId, String clientId) {
        System.out.println("2. [ Impl ] : changeCookieSetId");
        
        clientdao.changeCookieSetId(ckId, clientId);
    }
}
 

 

 

 

4. CilentDAO.java 클래스 수정

	// 쿠키해제(회원)
	public void changeCookieSetId(String ckId, String clientId) {
		System.out.println("3. [ Client DAO ] changeCookieSetId : " + clientId);
		
		HashMap<String, String> client = new HashMap<String, String>();
		client.put("ckId", ckId);
		client.put("clientId", clientId);
		
		sqlSessionTemplate.update("ClientDAO.changeCookieSetId", client);
	}
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
package com.w2.client;
 
import java.util.HashMap;
 
import javax.servlet.http.Cookie;
 
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
 
 
@Repository
public class ClientDAO {
    
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;
    
    // 중복 확인
    public int clientCheck(HashMap<StringString> check) {
        System.out.println("3. [ Client DAO ] clientCheck : " + check.toString());
        
        return sqlSessionTemplate.selectOne("ClientDAO.checkService", check);
    }
 
    // 회원 가입
    public int clientSignup(ClientVO client) {
        System.out.println("3. [ Client DAO ] clientSignup : " + client.toString());
        
        return sqlSessionTemplate.insert("ClientDAO.clientSignup", client);
    }
 
    // 회원 정보 가져오기
    public ClientVO getClient(String clientId) {
        System.out.println("3. [ Client DAO ] getClient : " + clientId);
        
        return sqlSessionTemplate.selectOne("ClientDAO.getClient", clientId);
    }
 
    // 최근 로그인 일자 저장
    public void setLogDate(String clientId) {
        System.out.println("8. [ Client DAO ] setLogDate");
        sqlSessionTemplate.update("ClientDAO.setLogDate", clientId);
    }
 
    // 아이디 찾기
    public String clientFindId(HashMap<StringString> info) {
        System.out.println("3. [ Client DAO ] clientFindId : " + info.toString());
        
        return sqlSessionTemplate.selectOne("ClientDAO.clientFindId", info);
    }
 
    // 비밀번호 찾기
    public int clientFindPwd(HashMap<StringString> info) {
        System.out.println("3. [ Client DAO ] clientFindPwd : " + info.toString());
        
        return sqlSessionTemplate.selectOne("ClientDAO.clientFindPwd", info);
    }
 
    // 비밀번호 변경
    public int clientSetPwd(ClientVO client) {
        System.out.println("3. [ Client DAO ] clientSetPwd : " + client.toString());
        
        return sqlSessionTemplate.update("ClientDAO.clientSetPwd", client);
    }
 
    // 마이페이지 기본 정보
    public HashMap<String, Object> clientSetMypage(String clientId) {
        System.out.println("3. [ Client DAO ] clientSetMypage : " + clientId);
        
        HashMap<String, Object> result = sqlSessionTemplate.selectOne("ClientDAO.clientSetMypage", clientId);
        
        if(result != null) {
            System.out.println("4. [ Client DAO ] 결과 : " + result.toString());
        }
        
        return result;
    }
 
    // 쿠키해제(회원)
    public void changeCookieSetId(String ckId, String clientId) {
        System.out.println("3. [ Client DAO ] changeCookieSetId : " + clientId);
        
        HashMap<StringString> client = new HashMap<StringString>();
        client.put("ckId", ckId);
        client.put("clientId", clientId);
        
        sqlSessionTemplate.update("ClientDAO.changeCookieSetId", client);
    }
}
 

 

 

 

5. client-mapping.xml 파일 수정

	<!-- 로그인 시 쿠키 정보 아이디로 변경하기 -->
	<update id="changeCookieSetId" parameterType="Map">
		UPDATE cart
		SET ckId = null, ckLimit = null, cId = #{ clientId }
		WHERE ckId = #{ ckId }
	</update>
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
<?xml version="1.0" encoding="UTF-8"?>
 
<!-- MyBatis 다운 파일 PDF 에서 붙여넣은 내용입니다. -->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
                 
<mapper namespace="ClientDAO">
    <resultMap type="com.w2.client.ClientVO" id="client">
        <id property="clientId" column="cId" />
        <result property="clientPwd" column="cPwd" />
        <result property="clientName" column="cName" />
        <result property="clientNum" column="cNum" />
        <result property="clientEmail" column="cEmail" />
        <result property="clientEmailCheck" column="cEmailCheck" />
        <result property="clientBirth" column="cBirth" />
        <result property="clientNickName" column="cNickName" />
        <result property="gradeId" column="grId" />
        <result property="clientPoint" column="cPoint" />
        <result property="clientLogDate" column="cLogDate" />
        <result property="chPwdDate" column="chPwdDate" />
    </resultMap>
    
    <!-- 사용 가능 
    <sql id="미리 지정가능">지정하고 싶은 값 입력 가능</sql>
    <include refid="미리 지정가능"/>
    -->
    
    <!-- 정보 중복 확인 -->
    <select id="checkService" resultType="int" parameterType="Map">
        SELECT COUNT(*) FROM client
        <choose>
            <when test="#{ comp eq 'cId' }">
                WHERE cId = #{ with }
            </when>
            <when test="#{ comp eq 'cNickName' }">
                WHERE cNickName = #{ with }
            </when>
            <when test="#{ comp eq 'cEmail' }">
                WHERE cEmail = #{ with }
            </when>
        </choose>
    </select>
    
    <!-- 회원 가입 -->
    <insert id="clientSignup" parameterType="client">
        INSERT INTO client (cId, cPwd, cName, cNum, cEmail, cEmailCheck, cBirth, cNickName, grId, cPoint)
        VALUES (#{ clientId }, #{ clientPwd }, #{ clientName }, #{ clientNum }, #{ clientEmail }, #{ clientEmailCheck }, 
                #{ clientBirth }, #{ clientNickName }, #{ gradeId }, #{ clientPoint });
    </insert>
    
    <!-- 회원 정보 조회 -->
    <select id="getClient" parameterType="String" resultMap="client">
        SELECT * FROM client WHERE cId=#{ clientId }
    </select>
    
    <!-- 마지막 로그인 일자 업데이트 -->
    <update id="setLogDate" parameterType="String">
        UPDATE client SET cLogDate = CURRENT_TIMESTAMP WHERE cId = #{ clientId }
    </update>
    
    <!-- 아이디 찾기 -->
    <select id="clientFindId" parameterType="Map" resultType="String">
        SELECT cId FROM client WHERE cName = #{ clientName } AND ${ type } = #{ keyword }
    </select>
    
    <!-- 비밀번호 찾기 -->
    <select id="clientFindPwd" parameterType="Map" resultType="int">
        SELECT COUNT(*) FROM client 
        WHERE cId = #{ clientId } 
        AND cName = #{ clientName }
        AND ${ type } = #{ keyword }
    </select>
    
    <!-- 비밀번호 변경 -->
    <update id="clientSetPwd" parameterType="client">
        UPDATE client SET cPwd = #{ clientPwd }, chPwdDate = CURRENT_TIMESTAMP
        WHERE cId = #{ clientId }
    </update>
    
    <!-- 마이페이지 기본 정보 -->
    <select id="clientSetMypage" parameterType="String" resultType="HashMap">
        SELECT 
            client.cPoint as point, 
            IFNULL((LENGTH(client.cmarkList) - LENGTH(REPLACE(client.cmarkList, ', '''))), 0) as wish,
            COUNT(orders.cid) as "order",
            COUNT(coupon_list.cId) as coupon,
            COUNT(review.cId) as review
        FROM client
        LEFT JOIN orders ON client.cId = orders.cid
        LEFT JOIN coupon_list ON client.cId = coupon_list.cId
        LEFT JOIN review ON client.cId = review.cId
        WHERE client.cId = #{ clientId }
        GROUP BY client.cId;
    </select>
    
    <!-- 로그인 시 쿠키 정보 아이디로 변경하기 -->
    <update id="changeCookieSetId" parameterType="Map">
        UPDATE cart
        SET ckId = null, ckLimit = null, cId = #{ clientId }
        WHERE ckId = #{ ckId }
    </update>
</mapper>

 

 

reProject_19_Spring Scheduler 이용해서 만료된 쿠키에 적용하기

reProject_18_Spring Schedular 이용해서 만료된 쿠키에 적용하기 구현 준비 reProject_17_쇼핑몰 상품 재고 반영, 장바구니 수량 변경 적용 구현 reProject_16_ 장바구니 기능 구현 수정, 재고 수량 적용 reProject_

hyeonga493.tistory.com

 

반응형