tiger
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 | package Pack01; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller public class Tiger { @RequestMapping("t6") String func06(Model model, String nickname, int salary) { model.addAttribute("k1", nickname); model.addAttribute("k2", salary); //앞이 뷰에서 쓸것 뒤에것이 들어온것 System.out.println(nickname+salary); return "LionView"; } @RequestMapping("t7") ModelAndView func07(Model model, String nickname, int salary) { ModelAndView mv = new ModelAndView("LionView"); //모델엔뷰객체 라이언뷰로 보내는 다른방법중하나 mv.addObject("f1",nickname); mv.addObject("f2",salary); System.out.println(nickname+salary); return mv; } @RequestMapping("t8") String func08(Model model, HttpServletRequest hsr) { String s = (String)hsr.getParameter("nickname"); String n = (String)hsr.getParameter("salary"); //parameter는 String바께 안되므로 받은후에 다시 바꿔줘야된다. model.addAttribute("k11",s); model.addAttribute("k22",n); return "LionView"; //modelandview랑 같이 사용가능 } @RequestMapping("t9") String func09() { return "LionView"; } @RequestMapping("t10") ModelAndView func010(int salary) { //던지는 거 model로 ModelAndView mv; if(salary%2==0) { mv = new ModelAndView("TigerView"); } else { mv = new ModelAndView("LionView"); } return mv; } @RequestMapping("t11") ModelAndView func011(int salary) { //던지는 거 model로 ModelAndView mv; if(salary%2==0) { mv = new ModelAndView("TigerView"); } else { mv = new ModelAndView("LionView"); } return mv; } @RequestMapping("t12")
String func012(Model model,HttpServletRequest hsr) {
Coffee c = (Coffee)hsr.getAttribute("coffee");
model.addAttribute("k11",c);
return "LionView";
} @RequestMapping("t18") String func018(Model model,Coffee coffee) { System.out.println(coffee.getNickname()); System.out.println(coffee.getSalary()); return "LionView"; } } | cs |
view
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 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html> <html> <head> <meta charset="EUC-KR"> <title>Insert title here</title> </head> <body> 라이언 뷰다 ${k11 } ${k22 } ${f1 } ${f2 } <% String n = (String) request.getAttribute("nickname"); String s = (String) request.getAttribute("salary"); %> <%
String c = (String)request.getAttribute("coffee");
%> <!-- el --> ${coffee.nickname} ${coffee.salary} ${coffee.getNickname()} ${coffee.getSalary()} --%> <!-- ls --> ${n.getNickname } ${s.getSalary } </body> </html> | cs |
728x90
댓글