最近打算将post方法拆分成post和put时,接口参数放到body中,put接口参数映射不到数据。但在之前的一个项目又是可以的,对比了下两个项目,之前项目用的springBoot版本哪位2.0.3.Release,新项目用的版本为2.3.2.Release。
之前项目通过以下方式的配置可以支持put接口映射参数:
public class WebConfig extends WebMvcConfigurationSupport {
@Bean
public HttpPutFormContentFilter httpPutFormContentFilter() {
return new HttpPutFormContentFilter();
}
}
将代码复制过来时,发现httpPutFormContentFilter方法已经被删除了,HttpPutFormContentFilter 也被标记为@deprecated,源码注释如下,从SpringMVC5.1开始已被弃用了。
/*
* ....
* @author Rossen Stoyanchev
* @since 3.1
* @deprecated as of 5.1 in favor of {@link FormContentFilter} which is the same
* but also handles DELETE.
*/
@Deprecated
public class HttpPutFormContentFilter extends OncePerRequestFilter {
.....
}
针对put映射body参数,SpringMVC提供了新的类FormContentFilter。FormContentFilter类和HttpPutFormContentFilter类的区别,前者比后者多处理了DELETE请求,配置方法如下:
@SpringBootApplication
@Import( FormContentFilter.class )
public class SpringApplication {
public static void main(String[] args) {
SpringApplication.run(SpringApplication.class, args);
}
}
或者
@Configuration
@Import( FormContentFilter.class )
public class FormContentConfig {}
部分springBoot和springMVC的版本关系:
springBoot版本 | springMVC版本 |
---|---|
2.0.3 | 5.0.7 |
2.0.4 | 5.0.8 |
2.0.5 | 5.0.9 |
2.0.6 | 5.0.10 |
2.3.2 | 5.2.8 |
网友评论