spring的常用标签有哪些?针对这个问题,今天小编总结了这篇文章,希望能帮助更多想解决这个问题的朋友找到更加简单易行的办法。
1:@RequestParam
作用:吧请求中指定名称的参数给控制器中的形参赋值
属性 :required :请求参数中是否必须提供此参数。默认值:true ,表示必须提供条件,否则报错,改为false,不会报错

成都创新互联是一家专注于成都网站设计、网站建设与策划设计,康马网站建设哪家好?成都创新互联做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:康马等地区。康马做网站价格咨询:18980820575


当没有接到值不会报错,会显示null

2:@RequestBody
作用: 用于获取请求体内容。直接使用得到是key=value& key
=value..结构数据
get 请求不适用
属性 :required :是否必须有请求体,默认值true.当取值为true时,get请求方式会报错。如果取值为false,get请求得到null。


3:3.@ResponseBody
作用
用于方法上
当return返回json类型的时候,也要用这个注解,他能帮助json封装数据,此时return 后面的就被封装了,此时return不会被视图解析器理解为跳转页面。
4:@RequestHeader
作用:用于获取请求消息头
属性:
value :提供消息头名称
required :是否必须有此消息头
注意:
在实际开发中一般不用


5: @CookieValue
作用:用于指定的cookie名称的值传入控制器方法参数
属性
value:指定的Cookie
required : 是否必须有此cookie


6:@ModelAttribute
作用:该表单是 SpringMVC4.3版本之后新加入的。他可以用于修饰方法和参数。
出现在方法上,表示当前方法会在控制器方法之前执行,先执行。他可以修饰没有返回值的方法,也可以修饰具体的方法。



出现在参数上,获取指定的数据给参数赋值
属性:
value : 用于获取数据的key。key也可以是POST的属性名称,也可以是map结构的key,
应用场景:
当表单提交数据不完整的实体类数据时保证没有提交数据的字段使用数据库对对象原来的数据,
例如:
我们在编辑一个用户时,用户有一个创建信息字段,该字段的值是不准被修改。在提交表单数据是肯定没有此字段的内容,一旦跟新会把该字段内容置为null,此时就可以使用此注解解决问题。
7:SessionAttribute
作用:用于多次执行控制器方法间参数共享
属性:
value: 用于指定存入的属性名称
type : 用于指定存入的数据类型








看完上述内容,你们对spring的常用标签有进一步的了解吗?如果还想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读。
分享文章:spring的常用标签有哪些
当前路径:
http://cqcxhl.cn/article/jpsicc.html