exp:Controller类里的参数注解

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tonghuawanli/article/details/82379973

package org.springframework.web.bind.annotation;

1、@RequestParam String identityCardId:URL里的传输参数;

2、(@RequestBody User user):由前端传来的json数据,RequestBody接收的是用POST方式请求的放在body里的json数据,实际上如果body里是json数据,除了上面的用对象接收数据,也可以用简单的String来接收。如( @RequestBody String jsonString )
参考:
https://blog.csdn.net/justry_deng/article/details/80972817

3、@ModelAttribute:可以用在方法参数或方法体上。用在参数时用于与页面的数据交互,例如:前端有form,

<form:form modelAttribute="book" method="POST" action="show.do"> 
<table> 
.....
</table> 
</form:form>

在后端类里就可以用@ModelAttribute Book book接收。

4、@RequestAttribute Long userId:
可以被用于访问由过滤器或拦截器创建的、预先存在的请求属性
也就是事先存在了例如 request.setAttribute(“userId”,1687);
然后再从这次request中取出这个属性。
(补:还有request.getSession().setAttribute(),关于request、session等更多,见
https://blog.csdn.net/sinat_15274667/article/details/51585538?utm_source=blogxgwz4)

5、@RequestPart(required = true) MultipartFile userFile
用于文件上传。

猜你喜欢

转载自blog.csdn.net/tonghuawanli/article/details/82379973