마음은 조급한데 진도가 왜 이렇게 더디게 나가는지 모르겠다.
매일 할 건 계속 쌓여가는 느낌
무튼 결과는 아래와 같이 나온다.
컨펌창을 한번 더 띄워서 정말 탈퇴할건지 확인받고.. 근데 지금 보니까 너무 가지말라고 소리치는거 같네... 소문자로 바꿔야겠다 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
1. view (Leave.jsp)
조건
1. 입력한 아이디,비번이 로그인된 아이디,비번과 같을 것 (else if)
2. 당연하지만 id,pw 창이 빈칸이지 않을 것 (if)
$(document).ready(function(){
$('#leaveBtn').click(function(){
//valid ID check
if ($('#LeavemId').val() == '') {
alert('plese input your ID.');
return false;
} else if ($('#LeavemId').val() != '${loginUser.mId}') {
alert('Please check your ID.');
return false;
}
//valid PW check
if ($('#LeavemPw').val() == '') {
alert('please input your Password.');
return false;
} else if ($('#LeavemPw').val() != '${loginUser.mPw}') {
alert('Please check your Password.');
return false;
}
if ( !confirm('Your account will be PERMANENTLY deleted.')){
return false;
}
$.ajax({
url: '/MYHOME_P/leave.member',
dataType: 'json',
success: function(obj) {
if (obj.isSuccess){
alert('We have now permanently deleted your user account. You are alawys welcome to join again!');
location.href='/MYHOME_P/index.member'
} else {
alert('We could\'t delete your user account some reasons.');
history.back();
}
},
error: function() {
alert('error');
}
});
});
});
2. Controller
case "/leave.member" :
ajaxCommand = new LeaveCommand();
result = ajaxCommand.execute(request, response);
out.print(result);
break;
3. Command
* 기본이 되는 ajaxcommand interface
public interface AjaxCommand {
public String execute(HttpServletRequest request, HttpServletResponse response)throws Exception;
}
어차피 뷰페이지 스크립트에서 id, pw 검사를 진행하고 왔기 때문에 백엔드에서는 아이디로 그 유저만 찾아서 삭제해 준다.
쿼리문을 실행하고 성공하면 (결과값이 0보다 크면) 성공했다는 메세지를 보내준다.
4. Dao
sql에 맵퍼대로 mDto를 딜리트해주고, 그 결과값이 0보다 크면 커밋한다.
public int memberDelete(String mId) {
SqlSession ss = factory.openSession(false);
int result = ss.delete("mybatis.mapper.member.memberDelete",mId);
if (result >0) {
ss.commit();
}
ss.close();
return result;
}
5. xml
<delete id="memberDelete" parameterType="String">
DELETE
FROM MEMBER2
WHERE MID = #{mId}
</delete>
'Project > 2. My First Website <Mybatis>' 카테고리의 다른 글
project 3.1 My first website/ 게시판 리스트 (0) | 2020.09.13 |
---|---|
project 2.5 My first website/ 회원정보 변경 페이지 (0) | 2020.09.12 |
project 2.3 My first website/ 회원가입 페이지 (0) | 2020.09.07 |
project 2. 2 My first website/ 아이디, 비밀번호 찾기 페이지 (0) | 2020.09.06 |
project 2. 1 My first website/ Mybatis란? 그리고 login 페이지만들기 (0) | 2020.09.06 |