首页 > 代码库 > 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