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

时间:2019-08-19
本文章向大家介绍【Spring】【5】 PUT请求接收不到参数,主要包括【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

原文地址:https://www.cnblogs.com/huashengweilong/p/11374912.html