[转]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.注册java程序为LINUX系统服务的总结。
paip.注册java程序为LINUX系统服务的总结. ////////////////实现开机启动. 标准方法是按照/etc/init.d/下面的文件,修改一下:然后chkconfig xxx on ...
- piap.excel 微软 时间戳转换mssql sql server文件时间戳转换unix 导入mysql
piap.excel 微软 时间戳转换mssql sql server文件时间戳转换unix 导入mysql 需要不个mssql的sql文件导入mysql.他们的时间戳格式不同..ms用的是自定义的时 ...
- FreeMarker模板语法
四.FreeMarker模板语法 要编写复杂的模板需要熟悉FreeMarker语法规则,官网有详细说明,中文帮助也比较详细了,下面这些内容是从网上收罗来的,感谢网友的分享,经过整理与修改的内容如下.建 ...
- Leetcode 206 Reverse Linked List 链表
将单向链表反转 完成如图操作,依次进行即可 1 2 3 /** * Definition for singly-linked list. * struct ListNode { * int val; ...
- How Tomcat works — 五、tomcat启动(4)
前面摆了三节的姿势,现在终于要看到最终tomcat监听端口,接收请求了. 目录 Connector Http11Protocol JIoEndpoint 总结 在前面的初始化都完成之后,进行Conne ...
- eclipse安装activiti工作流插件
方式一:在有网络的情况下,安装流程设计器步骤如下: 1.点击eclipse上方工具栏的Help,选择Install New Software 2.弹出如下窗口,然后填写插件名称和安装地址 Name: ...
- Socket编程基本流程实践
通讯基本流程图如下所示: Server端代码(ServerDemo.cpp): #include <WinSock2.h> #include <Windows.h> #incl ...
- Code Consultation
Need help architecting or coding your application? You can get technical help with building applicat ...
- IOS6屏幕旋转详解(自动旋转、手动旋转、兼容IOS6之前系统)
转自 http://blog.csdn.net/zzfsuiye/article/details/8251060 概述: 在iOS6之前的版本中,通常使用 shouldAutorotateToInte ...
- Scala 深入浅出实战经典 第79讲:单例深入讲解及单例背后的链式表达式
王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-87讲)完整视频.PPT.代码下载:百度云盘:http://pan.baidu.com/s/1c0noOt6 ...