解决SpringBoot下delete请求不可用There was an unexpected error (type=Method Not Allowed, status=405).
程序员文章站
2024-03-25 17:16:40
...
1、页面提交delete请求,出现Whitelabel Error Page错误
<button th:attr="aaa@qq.com{/emp/}+${emp.id}" class="btn btn-sm btn-danger deleteBtn">删除</button>
<form id="deleteEmpForm" method="post">
<input type="hidden" name="_method" value="delete"/>
</form>
<script>
$(".deleteBtn").click(function(){
//删除当前员工的
$("#deleteEmpForm").attr("action",$(this).attr("del_uri")).submit();
return false;
});
</script>
解决办法
只需要在SpringBoot配置中【application.properties】配置:
spring.mvc.hiddenmethod.filter.enabled=true