ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๋ฐ˜์‘ํ˜•

Controller


UsersController

//withdrawal ํƒˆํ‡ด ํŽ˜์ด์ง€ ์š”์ฒญ
@GetMapping("/withdrawal")
public ModelAndView remove() {
	return new ModelAndView ("user/withdrawal");
}

withdrawal.jsp๋กœ ์ด๋™

 

//ํƒˆํ‡ด ์š”์ฒญ
@PostMapping("/withdrawal")
public String withdrawal(@RequestBody UsersVO user, HttpSession session) throws Exception {
	
	//๋น„๋ฐ€๋ฒˆํ˜ธ ๋งž๋Š”์ง€ ํ™•์ธ
	String result = checkPw(user.getPw(), session);
	
	if(result.equals("pwConfirmOK")) {
		//ํƒˆํ‡ด ์‹œํ‚ค๊ณ 
		usersService.withdrawal(user);
		
		//๋กœ๊ทธ์ธ์„ธ์…˜ ์‚ญ์ œ
		Object object = session.getAttribute("login");
		if(object != null) {
			session.removeAttribute("login");
			session.invalidate();
		}
		
		result = "Success";
	} else {
		//๋น„๋ฒˆ ํ‹€๋ฆผ
		result ="Fail";
	}
	
	return result;	
}

ํšŒ์› ํƒˆํ‡ดํ•˜๊ธฐ ์ „์— ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ๋งž๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. ๋น„๋ฐ€๋ฒˆํ˜ธ ์ฐพ๊ธฐ์—์„œ ๋งŒ๋“ค์–ด๋†“์€ ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด์„œ ํ™•์ธํ•˜์˜€๋‹ค. ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•˜๋ฉด DB์—์„œ ํ•ด๋‹น ํšŒ์›์„ ์‚ญ์ œํ•˜๊ณ  ์„ธ์…˜์— ์ €์žฅ๋œ ๋กœ๊ทธ์ธ์ •๋ณด ์„ธ์…˜์„ ์‚ญ์ œํ•ด์ค€๋‹ค.

 

 

 

Service


UsersService

//ํšŒ์› ํƒˆํ‡ด
@Transactional
@Override
public void withdrawal(UsersVO user) throws Exception {

	//ํ”„๋กœํ•„ ์‚ฌ์ง„ ์‚ญ์ œ
	usersDAO.deleteUserImg(user.getUserNo());
	
	//ํƒˆํ‡ด ์ง„ํ–‰
	usersDAO.withdrawal(user);
}

ํšŒ์› ํƒˆํ‡ด์‹œ ํšŒ์›์˜ ํ”„๋กœํ•„์‚ฌ์ง„์˜ ์ •๋ณด๋ฅผ ๋™์‹œ์— ์‚ญ์ œ๋ฅผ ํ•ด์ฃผ์–ด์•ผํ•œ๋‹ค.

+

//ํšŒ์› ํƒˆํ‡ด
@Transactional
@Override
public void withdrawal(UsersVO user) throws Exception {
	
	//๊ด€๋ จ ๊ฒŒ์‹œ๊ธ€ ์‚ญ์ œ
	postsDAO.deleteUserAllPost(user.getUserNo());
	//ํŒ”๋กœ์šฐ ์‚ญ์ œ
	followDAO.deleteUserAllFollow(user.getUserNo());
	//ํ”„๋กœํ•„ ์‚ฌ์ง„ ์‚ญ์ œ
	usersDAO.deleteUserImg(user.getUserNo());
	
	//ํƒˆํ‡ด ์ง„ํ–‰
	usersDAO.withdrawal(user);
		
}

Post์™€ Follow ๊ตฌํ˜„ ํ›„ ํƒˆํ‡ด์‹œ์— ๊ด€๋ จ ๊ฒŒ์‹œ๊ธ€๊ณผ ํŒ”๋กœ์šฐ, ํŒ”๋กœ์›Œ ์ •๋ณด๋“ค๋„ ์ „๋ถ€ ์‚ญ์ œ๋ฅผ ํ•ด์ฃผ์–ด์•ผํ•œ๋‹ค.

 

 

 

๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€