Spring MVC数据绑定
2015-05-11 14:30
197 查看
public String other(Locale locale, Principal principal)
java.util.Locale:得到当前请求的本地化信息,默认等价于ServletRequest.getLocale(),如果配置LocaleResolver解析器则由它决定Locale,后续介绍;
java.security.Principal:该主体对象包含了验证通过的用户信息,等价于HttpServletRequest.getUserPrincipal()。
http://jinnianshilongnian.iteye.com/blog/1698916
且不能直接绑定到map,list,set等,因为他们是接口 ,并不能实例化,若要绑定到其中,需要放在某个bean中。
1、参数与值对,一大堆参数与一大堆值对,form提交时常用
![](http://images.cnitblog.com/blog2015/709570/201505/111542365648492.png)
这种,Spring mvc可以直接在后台绑定到方法的参数中,如参数为permissions,则就可以直接绑定到该参数上。
2、json字符串型
以{}为开始与结束的标志
![](http://images.cnitblog.com/blog2015/709570/201505/111549125489083.png)
这种对于没有插件的Spring来说是无法绑定的,要绑定则需要
使用时机:
A) GET、POST方式提时, 根据request header Content-Type的值来判断:
application/x-www-form-urlencoded, 可选(即非必须,因为这种情况的数据@RequestParam, @ModelAttribute也可以处理,当然@RequestBody也能处理);
multipart/form-data, 不能处理(即使用@RequestBody不能处理这种格式的数据);
其他格式, 必须(其他格式包括application/json, application/xml等。这些格式的数据,必须使用@RequestBody来处理);
B) PUT方式提交时, 根据request header Content-Type的值来判断:
application/x-www-form-urlencoded, 必须;
multipart/form-data, 不能处理;
其他格式, 必须;
说明:request的body部分的数据编码格式由header部分的Content-Type指定;
java.util.Locale:得到当前请求的本地化信息,默认等价于ServletRequest.getLocale(),如果配置LocaleResolver解析器则由它决定Locale,后续介绍;
java.security.Principal:该主体对象包含了验证通过的用户信息,等价于HttpServletRequest.getUserPrincipal()。
http://jinnianshilongnian.iteye.com/blog/1698916
且不能直接绑定到map,list,set等,因为他们是接口 ,并不能实例化,若要绑定到其中,需要放在某个bean中。
浅谈 SpringMVC 数据绑定
页面传数据有两种方式1、参数与值对,一大堆参数与一大堆值对,form提交时常用
![](http://images.cnitblog.com/blog2015/709570/201505/111542365648492.png)
这种,Spring mvc可以直接在后台绑定到方法的参数中,如参数为permissions,则就可以直接绑定到该参数上。
2、json字符串型
以{}为开始与结束的标志
![](http://images.cnitblog.com/blog2015/709570/201505/111549125489083.png)
这种对于没有插件的Spring来说是无法绑定的,要绑定则需要
扩展SpringMVC以支持绑定JSON格式的请求参数
或者可以使用@RequestBody把整个请求作为整体传递给后台使用时机:
A) GET、POST方式提时, 根据request header Content-Type的值来判断:
application/x-www-form-urlencoded, 可选(即非必须,因为这种情况的数据@RequestParam, @ModelAttribute也可以处理,当然@RequestBody也能处理);
multipart/form-data, 不能处理(即使用@RequestBody不能处理这种格式的数据);
其他格式, 必须(其他格式包括application/json, application/xml等。这些格式的数据,必须使用@RequestBody来处理);
B) PUT方式提交时, 根据request header Content-Type的值来判断:
application/x-www-form-urlencoded, 必须;
multipart/form-data, 不能处理;
其他格式, 必须;
说明:request的body部分的数据编码格式由header部分的Content-Type指定;
相关文章推荐
- spring mvc 数据绑定报错 Failed to convert property value of type 'java.lang.String' to required type 'int'
- Spring MVC数据绑定
- Spring MVC数据绑定的扩展
- Spring MVC 复杂数据绑定
- Spring MVC中数据绑定之日期类型
- spring mvc使用@InitBinder 标签对表单数据绑定
- Spring MVC数据绑定大全
- spring mvc使用@InitBinder 标签对表单数据绑定
- spring mvc 数据绑定问题 提交表单提示HTTP status 400, The request sent by the client was syntactically incorrect
- Spring MVC数据绑定大全
- Spring MVC 数据绑定
- Spring MVC数据绑定(一) 数据转换
- spring mvc 多个bean,或一个bean多个对象的数据绑定
- spring mvc 数据绑定 400错误
- JavaEE_Mybatis_SpringMVC__Spring MVC中数据绑定之日期类型
- spring mvc3(对象传参 Date 类型数据绑定)
- Spring MVC数据绑定大全
- Spring MVC 自学杂记(二) -- 数据绑定之日期转换
- (笔记)Spring MVC学习指南_数据绑定和表单标签库
- spring mvc使用@InitBinder 标签对表单数据绑定