[转]SpringMVC Controller&View数据传递
Spring MVC3在controller和视图之间传递参数的方法:
@RequestMapping(value={"/","/hello"})
public String hello(int id,Map<String,Object> map) {
System.out.println(id);
System.out.println("hello");
map.put("hello", "world");
return "hello";
}
@RequestMapping(value="/say")
public String say(@RequestParam int id,Model model) {
System.out.println("say");
model.addAttribute("hello", "value");
//使用Object的类型作为key,String-->string
model.addAttribute("ok");
return "hello";
}
@RequestMapping("hello3")
public String hello3( @RequestParam("name" ) String name,
@RequestParam("hobby" ) String hobby){
System. out.println("name=" +name);
System. out.println("hobby=" +hobby);
return "hello" ;
}
@RequestMapping("/hello4" )
public String hello4(User user){
System.out.println("user.getName()=" +user.getName());
System.out.println("user.getHobby()=" +user.getHobby());
return "hello";
}
public class User {
private String name ;
private String hobby ;
public User(){
}
public User(String name, String hobby) {
this.name = name;
this.hobby = hobby;
}
//...get/set方法略
则页面上可以用
<form name="form1" action="hello4" method="post">
<input type="text" name="name"/>
<input type="text" name="hobby"/>
...
提交后,把值直接绑定到user对象上。
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter </filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf8</param-value>
</init-param>
</filter> <filter-mapping>
<filter-name>encodingFilter</filter-name >
<url-pattern>/*</url-pattern>
</filter-mapping>
[转]SpringMVC Controller&View数据传递的更多相关文章
- Controller与View数据传递 多Model传递
1)ViewBag变量方式 使用4个ViewBag变量进行数据传递,Data1.Data2.Data3.Data4的数据直接从数据库里调. Control中伪代码如下所示: 1 public Acti ...
- springMVC:将controller中数据传递到jsp页面
1> 将方法的返回值该为ModelAndView在返回时,将数据存储在ModelAndView对象中如: newModelAndView("/WEBINF/jsp/showData.j ...
- ASP.NET controller TO view 数据传递
https://stackify.com/viewbag/ In the case of ASP.NET MVC, you have three ways to pass data from the ...
- SpringMVC之json数据传递
json是一种常见的传递格式,是一种键值对应的格式.并且数据大小会比较小,方便传递.所以在开发中经常会用到json. 首先看一下json的格式: {key1:value1,key2:value2} 每 ...
- springmvc中的数据传递
import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; impo ...
- SpringMVC Controller 接收页面传递的中文参数出现乱码
在Controller中接收到的POST参数如果是中文的话,显示为乱码.已知客户端传过来时编码为UTF-8. 问题产生分析: spring MVC中默认的编码格式为“ISO-8859-1”,因此造成乱 ...
- ASP.NET MVC3中Controller与View之间的数据传递总结
一. Controller向View传递数据 1. 使用ViewData传递数据 我们在Controller中定义如下: ViewData["Message_ViewData& ...
- ASP.NET MVC3中Controller与View之间的数据传递
在ASP.NET MVC中,经常会在Controller与View之间传递数据,因此,熟练.灵活的掌握这两层之间的数据传递方法就非常重要.本文从两个方面进行探讨: 一. Controller向Vie ...
- Asp.net MVC中 Controller 与 View之间的数据传递
在ASP.NET MVC中,经常会在Controller与View之间传递数据 1.Controller向View中传递数据 (1)使用ViewData["user"] (2)使用 ...
随机推荐
- paip.代码生成器数据源格式最佳实践
paip.代码生成器数据源格式最佳实践 需要满足几个条件. 1.基于文本 2.容易的编辑.. 3,容易的代码解析. 这样,常用的设计工具powerdesign cdm pdm就排除兰...cdm虽然是 ...
- iOS7初体验(3)——图像资源Images Assets
开始之前,首先回顾一下iOS7初体验(1)——第一个应用程序HelloWorld中的一张图,如下所示: 本文便分享一下Images.xcassets的体验~_~ 1. 打开此前使用过的HelloWor ...
- Java中long和Long有什么区别 (转载)
“Long is a class. long is a primitive. That means Long can be null, where long can't. Long can go an ...
- 解决Visual Studio 2010/2012的RC4011 warnings
如果在vc10/11工程的rc文件中有以下任意一行代码: #include <winuser.h> #include <richedit.h> 那么vc将会给出一对警告: C: ...
- ubuntu bless 16字节每行
打开Preferences配置 输入路径:/usr/share/bless/bless-16-bytes-per-row.layout 或者使用以下配置 cat /home/scue/.config/ ...
- 如何配置 URLScan 工具
本文分步说明如何配置 URLScan 工具以防止 Web 服务器受到攻击和利用. 安装 URLScan 要安装 URLScan,请访问下面的 Microsoft Developer Network ( ...
- 启动和JQuery绑定--AngularJS学习笔记(二)
上一篇简单的分析了AngularJS的项目结构,后面就开始分析具体的源代码了. 从angularFiles.js中的定义可以看出有几个文件直接位于src根目录,并不是隶属于某个模块.这几 个分别是mi ...
- HDU 4686 Arc of Dream (矩阵快速幂)
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 【转】APP被苹果App Store拒绝的N个原因(持续补充)
作为iOS开发者,估计有很多都遇到过APP提交到App Store被拒,然后这些被拒的原因多种多样,今天dApps收集了常见的被拒的原因,以便更多开发者了解. 1.程序有重大bug,程序不能启动,或者 ...
- WPF下载远程文件,并显示进度条和百分比
WPF下载远程文件,并显示进度条和百分比 1.xaml <ProgressBar HorizontalAlignment="Left" Height="10&quo ...