前言:
接口改用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的博客 - 优快云博客
https://blog.youkuaiyun.com/asd1098626303/article/details/60868316
本文介绍了解决SpringMVC中PUT请求无法接收参数的问题,提供了三种解决方案:添加自定义过滤器、配置web.xml以及调整前端表单编码类型。

1285

被折叠的 条评论
为什么被折叠?



