【Spring】【5】 PUT请求接收不到参数

前言:

接口改用Restful风格后,发现PUT请求的接口,接收不到参数。

正文:

方法1:添加HttpPutFormContentFilter过滤器

我的使用场景是:SpringMVC。SpringBoot貌似不需要

import org.springframework.stereotype.Component;
import org.springframework.web.filter.HttpPutFormContentFilter;
 
@Component
public class PutFilter extends HttpPutFormContentFilter {
}

方法2:web.xml

也是用于SpringMVC。SpringBoot没有web.xml这个文件

<filter>
    <filter-name>HttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>HttpMethodFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

方法3:前端把enctype属性设置为application/x- www-form-urlencoded

参考博客:

springBoot PUT请求接收不了参数的解决办法 - asd1098626303的博客 - CSDN博客
https://blog.csdn.net/asd1098626303/article/details/60868316

猜你喜欢

转载自www.cnblogs.com/huashengweilong/p/11374912.html