@RequestBody和@RequestParam区别

@RequestParam

用来处理请求头Content-Type: 为 application/x-www-form-urlencoded编码的内容。(Http协议中,如果不指定Content-Type,则默认传递的参数就是application/x-www-form-urlencoded类型),get 方式中queryString的值,和post方式中 body data的值都会被Servlet接受到并转化到Request.getParameter()参数集中,所以@RequestParam可以获取的到。

RequestParam可以接受简单类型的属性,也可以接受对象类型。 
实质是将Request.getParameter() 中的Key-Value参数Map利用Spring的转化机制ConversionService配置,转化成参数接收对象或字段。

 @RequestBody

用来处理请求头Content-Type: 为 application/json编码的内容,明确的告诉服务器发送的内容是json。因为需要读取body中内容,所以只能接受post请求。

posted @ 2020-03-25 15:55  走路很快的大师兄  阅读(499)  评论(0)    收藏  举报