[转]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.输出内容替换在Apache 过滤器filter的设置
paip.输出内容替换在Apache 过滤器filter的设置 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog ...
- XML入门级的简单学习
xml案例<?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>Ge ...
- android eclipse关联源码,以及源码(代码)以及jar查看软件
1.eclipse关联源码 步骤一:自已百度下载相应版本的源码,我这里是4.2也就是API=17的版本. 步骤二:找到你安装sdk的目录, G:\Program Files\adt-bundle-wi ...
- How Tomcat works — 六、tomcat处理请求
tomcat已经启动完成了,那么是怎么处理请求的呢?怎么到了我们所写的servlet的呢? 目录 Http11ConnectionHandler Http11Processor CoyoteAdapt ...
- 一致性hash和solr千万级数据分布式搜索引擎中的应用
互联网创业中大部分人都是草根创业,这个时候没有强劲的服务器,也没有钱去买很昂贵的海量数据库.在这样严峻的条件下,一批又一批的创业者从创业中 获得成功,这个和当前的开源技术.海量数据架构有着必不可分的关 ...
- 【CUDA学习】GPU硬件结构
GPU的硬件结构,也不是具体的硬件结构,就是与CUDA相关的几个概念:thread,block,grid,warp,sp,sm. sp: 最基本的处理单元,streaming processor 最 ...
- DRAM 内存介绍(二)
参考资料:http://www.anandtech.com/show/3851/everything-you-always-wanted-to-know-about-sdram-memory-but- ...
- 混合使用Jquery Deferred和Angularjs的$timeout(转)
原文链接:http://my.oschina.net/gejiawen0913/blog/174826 <!DOCTYPE html> <html ng-app="Demo ...
- Android 实战之UI线程和Worker线程交互
哈哈,博文取了个比较霸气的名字,大家不都喜欢这样忽悠人吗 呵呵! 好了,现在就是很简单的点击查询,然后这个查询有点花时间,不想见面出现假死现象,所以在另外的线程进行查询. 好了,代码在此: packa ...
- C# 个人常用代码积累
/// <summary> /// TextBox限制只能输入十六进制,且只能输入6个 /// </summary> /// <param name="send ...