Spring mvc 值的传递
来源:互联网 发布:淘宝网消费者号码 编辑:程序博客网 时间:2024/05/21 16:22
1.view--->controller
1)public String welcome(@RequestParam("username") String username) 必须传递username 不然会报错404
2)直接在函数参数列表中添加参数接收 public String welcome(String username) 不强制必须传递username
2.controller--->view
1)用一个map 例如:Map<String, Object>context ,然后向context中put进去要传的参数,context.put("username", username)
package com.join.spring.controller;import java.util.Map;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;@Controllerpublic class HelloController {@RequestMapping("/hello")public String welcome(@RequestParam("username") String username,Map<String, Object> context) {context.put("username", username);System.out.println(username);return "welcome";}}
2)用Model来实现
package com.join.spring.controller;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;@Controllerpublic class HelloController {@RequestMapping("/hello")public String welcome(@RequestParam("username") String username,Model model) {model.addAttribute("username", username);System.out.println(username);return "welcome";}}
</pre><pre name="code" class="java">
0 0
- Spring mvc 值的传递
- spring mvc 获取后端传递的值
- Spring MVC 4值传递
- spring mvc中登录用户信息的传递
- Spring MVC List在前后台的传递
- Spring MVC参数的传递与接收
- spring MVC 的参数传递方式
- Spring MVC 传递参数
- Spring MVC 参数传递
- Spring mvc 传递数组
- spring MVC 参数传递
- spring MVC参数传递
- Spring mvc 参数传递
- Spring MVC中通过Jquery低版本的ajax传递参数值 遇到415的错误
- spring MVC session传递model
- spring mvc 传递 list 对象
- spring mvc 传递对象 二
- spring mvc 传递数组对象
- 数据因式分解
- android点击空白处隐藏键盘(亲测)
- Solr4.3---4.6删除数据的办法
- UVA11324-- The Largest Clique(SCC+DP)
- HDU 5053 the Sum of Cube
- Spring mvc 值的传递
- 堆和栈的区别
- 判断短字符串中的每个字符是否在长字符串都存在
- easyui Tab页动态控制
- 关闭archlinux等linux系统的BB提示音
- [Android Develop_003]-Android Database
- Android中Socket大文件断点上传
- Python 正则表达式验证Here Document(嵌入文档)
- UI设计—软件包装设计