关于Spring MVC的参数绑定
2016-02-12 00:07
639 查看
1、@PathVariable
@RequestMapping("/pets/{petId}")
public String test(@PathVariable String
string, Model model)
{
return string;
}
2、@RequestHeader
@RequestMapping("/pets/{petId}")
public String test(@@RequestHeader
String string, Model model)
{
return string;
}
获取Request
的header部分
Host
localhost:8080
Accept
text/html,application/xhtml+xml,application/xml;q=0.9
Accept-Language
fr,en-gb;q=0.7,en;q=0.3
Accept-Encoding
gzip,deflate
3、@CookieValue
把Request
header中关于cookie的值绑定到方法的参数上
如:
JSESSIONID=415A4AC178C59DACE0B2C9CA727CDD84
@RequestMapping("/displayHeaderInfo.do")
public void
displayHeaderInfo(@CookieValue("JSESSIONID") String
cookie) {
}
4、@RequestParam
简单类型的绑定,通过Request.getParameter()
获取的String可直接转换为简单类型的情况
public String getPata(@RequestParam("test") String
test, ModelMap model) {
return test;
}
5、@RequestBody
常用来处理Content-Type:
不是application/x-www-form-urlencoded编码的内容,例如application/json,
application/xml等;
它是通过使用HandlerAdapter
配置的HttpMessageConverters来解析post data body,然后绑定到相应的bean上的。
因为配置有FormHttpMessageConverter,所以也可以用来处理application/x-www-form-urlencoded的内容,处理完的结果放在一个MultiValueMap里,这种情况在某些特殊需求下使用,详情查看FormHttpMessageConverter api;
@RequestMapping(value = "/something", method =
RequestMethod.PUT)
public void handle(@RequestBody String body,
Writer writer) throws IOException {
writer.write(body);
}
6、@SessionAttributes
用来绑定HttpSession中的attribute对象的值
7、@ModelAttribute
将request级别的对象,变成session级别的,即,请求结束后会被保存起来,供其它方法使用
spring学习之@SessionAttributes详解
http://blog.csdn.net/li_xiao_ming/article/details/8349178
http://www.2cto.com/kf/201410/346482.html
hibernate之实体@onetomany和@manytoone双向注解
@RequestMapping("/pets/{petId}")
public String test(@PathVariable String
string, Model model)
{
return string;
}
2、@RequestHeader
@RequestMapping("/pets/{petId}")
public String test(@@RequestHeader
String string, Model model)
{
return string;
}
获取Request
的header部分
Host
localhost:8080
Accept
text/html,application/xhtml+xml,application/xml;q=0.9
Accept-Language
fr,en-gb;q=0.7,en;q=0.3
Accept-Encoding
gzip,deflate
3、@CookieValue
把Request
header中关于cookie的值绑定到方法的参数上
如:
JSESSIONID=415A4AC178C59DACE0B2C9CA727CDD84
@RequestMapping("/displayHeaderInfo.do")
public void
displayHeaderInfo(@CookieValue("JSESSIONID") String
cookie) {
}
4、@RequestParam
简单类型的绑定,通过Request.getParameter()
获取的String可直接转换为简单类型的情况
public String getPata(@RequestParam("test") String
test, ModelMap model) {
return test;
}
5、@RequestBody
常用来处理Content-Type:
不是application/x-www-form-urlencoded编码的内容,例如application/json,
application/xml等;
它是通过使用HandlerAdapter
配置的HttpMessageConverters来解析post data body,然后绑定到相应的bean上的。
因为配置有FormHttpMessageConverter,所以也可以用来处理application/x-www-form-urlencoded的内容,处理完的结果放在一个MultiValueMap里,这种情况在某些特殊需求下使用,详情查看FormHttpMessageConverter api;
@RequestMapping(value = "/something", method =
RequestMethod.PUT)
public void handle(@RequestBody String body,
Writer writer) throws IOException {
writer.write(body);
}
6、@SessionAttributes
用来绑定HttpSession中的attribute对象的值
7、@ModelAttribute
将request级别的对象,变成session级别的,即,请求结束后会被保存起来,供其它方法使用
spring学习之@SessionAttributes详解
http://blog.csdn.net/li_xiao_ming/article/details/8349178
http://www.2cto.com/kf/201410/346482.html
hibernate之实体@onetomany和@manytoone双向注解
相关文章推荐
- 如何处理大量并发用户访问网页,并且如何跟踪每个用户
- 从头认识Spring-2.1 自动装配(2)-byType(2)
- Struts2文件上传实例
- 从头认识Spring-2.1 自动装配(2)-byType(1)
- Struts2利用拦截器实现权限控制
- 从头认识Spring-2.1 自动装配(1)-byName
- java基础12多线程
- java中的构造方法
- java中的this
- java常见问题
- Java—设计模式(工厂模式)
- 栈的应用--四则运算表达式求值(java代码)
- JAVA比较两个日期相差的天数
- Arcgis server java develop begining
- Gradle教程Part2:java工程
- Java开发环境搭建
- java基础总结 --- enum枚举实现多路分发 石头、剪刀、布游戏示例
- The Java™ Tutorials — Concurrency :Memory Consistency Errors 内存一致性错误
- Spark学习笔记7-在eclipse里用scala编写spark程序(单机和集群运行)
- JDK中自带xml和对象互转方法