首页 > 代码库 > springMVC传值helloWorld
springMVC传值helloWorld
1 package com.test 2 @Controller 3 @RequestMapping("/dept/") 4 public class HelloWorldController { 5 @RequestMapping("index.action") 6 public ModelAndView index(HttpServletRequest request, 7 HttpServletResponse response) { 8 ModelAndView mav = new ModelAndView(); 9 mav.setViewName("welcome"); 10 return mav; 11 } 12 13 /* 14 * @RequestMapping("hello.action") public String hello(HttpServletRequest 15 * request,HttpServletResponse response,Model model){ String username = 16 * request.getParameter("username"); int age = 17 * Integer.parseInt(request.getParameter("age")); 18 * model.addAttribute("username",username); model.addAttribute("age",age); 19 * return "hello"; } 20 */ 21 22 /* 23 * @RequestMapping("hello.action") public String hello(HttpServletRequest 24 * request,HttpServletResponse response,ModelMap model){ String username = 25 * request.getParameter("username"); int age = 26 * Integer.parseInt(request.getParameter("age")); 27 * model.addAttribute("username",username); model.addAttribute("age",age); 28 * return "hello"; } 29 */ 30 31 /* 32 * @RequestMapping("hello.action") public String hello(String username,int 33 * age,Model model){ model.addAttribute("username",username); 34 * model.addAttribute("age",age); return "hello"; } 35 */ 36 /* 37 * @RequestMapping("hello.action") public String hello(UserInfo user,Model 38 * model){ model.addAttribute("username",user.getUsername()); 39 * model.addAttribute("age",user.getAge()); return "hello"; } 40 */ 41 /* 42 * @RequestMapping("hello.action") public String 43 * hello(@ModelAttribute("user1") UserInfo user){ return "hello"; } 44 */ 45 46 @RequestMapping("hello.action") 47 public String hello(@ModelAttribute UserInfo user) { 48 return "redirect:helloSecond.action"; 49 } 50 51 @RequestMapping("helloSecond.action") 52 public String helloSecond() { 53 return "hello"; 54 } 55 56 }
springMVC传值helloWorld
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。