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 }

 

转载于:https://www.cnblogs.com/xiaocainiaohuzhuo/p/7343864.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值