最近开发的项目中,使用了采用put方式更新数据记录,但是当和前端结合时,发现无法通过@NotBlank的验证器验证。一开始以为是前端同学的参数名称设置的不对,但是查阅资料后发现是SpringBoot配置有些问题。下面是详述。
一、问题名称:SpringBoot获取PUT方式提交参数为空
二、开发环境:SpringBoot 1.5.7 + Vue.js 2
三、解决方法:在WebMvcConfig中添加一个@Bean
1.修改配置:
@Configuration @EnableWebMvc public class WebMvcConfig extends WebMvcConfigurerAdapter { // 就是这个 @Bean public HttpPutFormContentFilter httpPutFormContentFilter() { return new HttpPutFormContentFilter(); } }
2.使用时:
@RequestMapping(method = RequestMethod.PUT) public ResponseEntity update(@Validated PutForm putForm){ /*Your Code Here*/ }问题解决。
本文介绍了一种在SpringBoot项目中解决PUT请求参数无法通过@NotBlank验证的问题的方法。通过在WebMvcConfig中添加HttpPutFormContentFilter Bean,可以正确解析PUT请求中的表单数据。
1万+





