//voidํ์ ๋ค์ด์จ ์์ฒญ ๊ฒฝ๋ก๊ฐ, ๋๊ฐ๋ ๊ฒฝ๋ก๊ฐ ๋ฉ๋๋ค(ํ๋ฉด๊ฒฝ๋ก)
@RequestMapping("/req_ex01")
public void ex01() {
}
@RequestMapping("/req_ex01")
public String ex01() {
return "request/req_ex01"; //ํ๋ฉด๊ฒฝ๋ก
}
//@RequestMapping(value = "/basic", method = RequestMethod.GET) //get๋ง ํ์ฉํจ
//@RequestMapping(value = "/basic", method = RequestMethod.POST) //post๋ง ํ์ฉํจ
//@RequestMapping("/basic") //get, post ๋๋ค ํ์ฉํจ
@RequestMapping(value = {"/basic", "/basic2"})
public String basic() {
System.out.println("basic์์ฒญ ์คํ๋จ");
return null;
}
//@GetMapping("/basic3") //๋ฆฌํ์คํธ๋งตํ + get๋งํ์ฉ
@PostMapping("/basic3") //๋ฆฌ์์คํธ๋งตํ + post๋งํ์ฉ
public String basic3() {
System.out.println("basic3์์ฒญ ์คํ๋จ");
return null;
}
//๋ฆฌํ์คํธ ๊ฐ์ฒด๋ก ๊ฐ ๋ฐ๊ธฐ
@RequestMapping(value = "/param", method = RequestMethod.POST)
public String param(HttpServletRequest request) {
System.out.println( request.getParameter("id") );
System.out.println( request.getParameter("pw") );
System.out.println( request.getParameterValues("inter") );
//์~~~~ ์ฒ๋ฆฌํด์~~
//๊ฒฐ๊ณผํ๋ฉด
return "request/req_ex02_ok";
}
//@RequestParam๋ฐฉ์ - ๋ฐ๋์ ๊ฐ์ ํ๋ฉด์์ ๋๊ฒจ์ผ ๋จ(ํ์)
//required = false ๋ ๊ฐ์ด ์๋๋ผ๋ ํต๊ณผํ๊ฒ ๋ฉ๋๋ค.
//defaultValue๋ ๊ฐ์ด ์์๋ ๊ธฐ๋ณธ๊ฐ์ ์ง์ ํ ์ ์์ต๋๋ค.
@RequestMapping(value = "/param", method = RequestMethod.POST)
public String param( @RequestParam("id") String x, //id๋ฅผ ๋ฐ์์ x๋งตํ
@RequestParam("pw") String y,
@RequestParam(value = "inter", required = false, defaultValue = "A") ArrayList<String> list ) {
System.out.println(x);
System.out.println(y);
System.out.println(list);
//์~~~~ ์ฒ๋ฆฌํด์~~
//๊ฒฐ๊ณผํ๋ฉด
return "request/req_ex02_ok";
}
@RequestMapping(value = "/param", method = RequestMethod.POST)
public String param( MemberVO vo ) {
System.out.println(vo.toString());
//์~~~~ ์ฒ๋ฆฌํด์~~
//๊ฒฐ๊ณผํ๋ฉด
return "request/req_ex02_ok";
}
//model์ ๋ฌ์
@RequestMapping("/res_ex02")
public String ex02(ModelMap model) {
model.addAttribute("data", "ํ๊ธธ๋"); //request.setAttribute(ํค, ๊ฐ)
model.addAttribute("now", new Date());
return "response/res_ex02";
}
//modelAndView์ ๋ฌ์
@RequestMapping("/res_ex02")
public ModelAndView ex02() {
ModelAndView mv = new ModelAndView();
mv.addObject("data", "์ด์์ "); //์ฌ๊ธฐ์ ๋ฐ์ดํฐ๋ฅผ ๋ด๋๋ค.
mv.addObject("now", new Date());
mv.setViewName("response/res_ex02"); //ํ๋ฉด์ ๋ํ ๊ฒฝ๋ก
return mv; //
}
//@ModelAttribute = ๋ฆฌํ์คํธ + modelํฉ์ฑ์ด
@RequestMapping("/res_ex03")
public String ex03( @ModelAttribute("info") String info ) {
System.out.println(info); //info๋ผ๋ ์ด๋ฆ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ๋๊ฒจ์ค๋๋ค.
return "response/res_ex03";
}
@RequestMapping("/res_ex04")
public String ex04( @ModelAttribute("info") MemberVO vo) { //vo๋ก ๋งตํํ๊ณ info๋ก ๋๊ธด๋ค
System.out.println(vo.toString());
return "response/res_ex04";
}
//๋ฆฌ๋ค์ด๋ ํธ ๋ผ๋๊ฒ?
//์คํ๋ง์ ์ด๋๋ฐฉ์ ๊ธฐ๋ณธ์ด forward์
๋๋ค
//redirect๋ ๋ค์ ๋ค์ ์ปจํธ๋กค๋ฌ๋ฅผ ํ์ฐ๋ ์ฉ๋๋ก ์ฌ์ฉํฉ๋๋ค.
//ํ๋ฉด์์ฒญ
@RequestMapping("/login")
public String loginView() {
System.out.println("๋ฆฌ๋ค์ด๋ ํธ ํ๊ณ ๋๊ฐ~");
return "response/login";
}
@RequestMapping(value = "/loginForm", method = RequestMethod.POST )
public String loginForm( MemberVO vo, RedirectAttributes ra ) {
//id๋ pw๊ฐ ๋์ผํ๋ฉด ๋ก๊ทธ์ธ ์ฑ๊ณต
String id = vo.getId();
String pw = vo.getPw();
if(id.equals(pw)) { //๋ก๊ทธ์ธ ์์ธ์ค
return "response/login_ok"; //์ด๋
} else { //๋ก๊ทธ์ธ ์คํจ
//๋ฆฌ๋ค์ด๋ ํธ๋ฅผ ๋ณด๋ผ๋, 1ํ์ฑ ํ๋ฐ๋ฐ์ดํฐ๋ก ๋ฐ์ดํฐ๋ฅผ ๋๊ธฐ๋ ๋ฐฉ์์ ์ ๊ณตํด์ค
ra.addFlashAttribute("msg", "ํ๋ ธ๋๋ฐ์?ใ
");
return "redirect:/response/login";
}
}