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

๋ฐ˜์‘ํ˜•

Controller


UsersController

//๋กœ๊ทธ์•„์›ƒ ์š”์ฒญ
@GetMapping("/logout")
public ModelAndView logout(HttpSession session) throws Exception {
	
	//์„ธ์…˜์—์„œ vo๊ฐ์ฒด๋ฅผ ๊บผ๋‚ด์˜จ๋‹ค.
	Object object = session.getAttribute("login");
	
	//์„ธ์…˜์— ๋กœ๊ทธ์ธ ์ •๋ณด๊ฐ€ ์žˆ๋‹ค๋ฉด
	if(object != null) {
		
		//login์„ธ์…˜์„ ์—†์•ค๋‹ค.
		session.removeAttribute("login");
		//์„ธ์…˜์˜ ์ •๋ณด๋ฅผ ์ดˆ๊ธฐํ™” ์‹œํ‚ด
		session.invalidate();
		
	}
	
	return new ModelAndView("redirect:/");
}

๋กœ๊ทธ์•„์›ƒ ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด ๋กœ๊ทธ์ธ ์„ธ์…˜์—์„œ vo๊ฐ์ฒด๋ฅผ ๊บผ๋‚ด์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ง€์›Œ๋ฒ„๋ฆฌ๊ณ  ํ˜„์žฌ ์„ธ์…˜์„ ๋ฌดํšจํ™” ์‹œ์ผœ์•ผํ•œ๋‹ค. DB์—์„œ ๋”ฐ๋กœ ํ•ด์ค„ ๊ฒƒ์€ ์—†์œผ๋ฏ€๋กœ ์„œ๋น„์Šค๋‹จ์—์„œ ํ•ด์ค„ ๊ฒƒ์€ ์—†๋‹ค. view์—์„œ๋Š” ๋กœ๊ทธ์•„์›ƒ ๋ฒ„ํŠผ์— ์š”์ฒญ ์ฒ˜๋ฆฌ๋งŒ ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

 

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