Spring-Boot2.4.5通过表单提交Delete请求
无法发出delete请求的原因
在Spring-Boot中MVC自动配置中WebMvcAutoConfiguration包含以下组件对请求方式进行定义。
@Bean
@ConditionalOnMissingBean(HiddenHttpMethodFilter.class)
@ConditionalOnProperty(prefix = "spring.mvc.hiddenmethod.filter", name = "enabled", matchIfMissing = false)
public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new OrderedHiddenHttpMethodFilter();
}
然后因为 @ConditionalOnProperty
注解使得该方式为条件注入,其中 matchIfMissing = false
指如果未进行属性配置,则自动配置不生效,即此时此组件不生效。如果matchIfMissing=true
,则表示如果没有对应的属性配置,则自动配置默认生效。
修改过滤器为启用
spring.mvc.hiddenmethod.filter.enabled = true
修改后该组件生效就可以自定义表单进行PUT和DELETE请求了