今天在使用RestFul 风格对请求的数据进行处理时,由于form表单只支持GET和POST请求,使用
<input type="hidden" name="_method" value="put"/>
修改请求方式,但是请求依旧是以表单POST的方式进行提交
解决方法: 原来是SpringBoot虽然给我们引入了HiddenHttpMethodFilter类进行请求的修改,但是该组件具有条件引入
@Bean
@ConditionalOnMissingBean({HiddenHttpMethodFilter.class})
@ConditionalOnProperty(
prefix = "spring.mvc.hiddenmethod.filter",
name = {"enabled"},
matchIfMissing = false
)
public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new OrderedHiddenHttpMethodFilter();
}
由于SpringBoot默认是不没有将该组件加载到容器的,因此还需要在配置文件中加入
spring.mvc.hiddenmethod.filter.enabled = true
本文介绍了解决在使用RestFul风格时,通过隐藏字段修改请求方式为PUT但实际仍为POST的问题。揭示了SpringBoot中HiddenHttpMethodFilter组件的作用及如何启用它。
2724

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



