码迷,mamicode.com
首页 > 编程语言 > 详细

springMVC传值helloWorld

时间:2017-08-11 10:02:10      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:cond   ppi   dir   传值   view   cti   model   welcome   nbsp   

 

 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

标签:cond   ppi   dir   传值   view   cti   model   welcome   nbsp   

原文地址:http://www.cnblogs.com/xiaocainiaohuzhuo/p/7343864.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!