springmvc的几个注解

1.获取请求头、cookie:@RequestHeader   @CookieValue


2.Controller类上标注@sessionAttributes: ModelandView、model,modelmap、map等都是储存在request域中,使用之可以暂存到session

该注解属性值为数组,可以指定具体的对象或具体的类型放到session。

3.Controller中的一个特别方法加上@ModelAttribute,会在所有mapping方法调用前执行mapping方法形参打上该注解可以在请求参数绑定前将上面模型中的对象绑定到形参


4.注解驱动作用:实例化处理映射器处理适配器异常解析器;1使用自定义类型转换器;2@NumberFormat3.@DateTimeFormat (页面的时间mvc要用Date接受须要该注解转化否则400错误或可以使用String接受)4.@Valid 5.@ResponseBody

5.JSR303和Hibernate validator @valid验证的对象后必须紧跟bindingresult 

6.@RequestBody:ajax传递的参数为一个json对象Controller可以用一个对象接收,如果是一个json对象的数组则需要@requestbody list接收;Ajax请求头要有contentType:application/json;charset=utf-8



猜你喜欢

转载自blog.csdn.net/qq_39506978/article/details/80197749
今日推荐