欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

解决SpringBoot下delete请求不可用There was an unexpected error (type=Method Not Allowed, status=405).

程序员文章站 2024-03-25 17:16:40
...

解决SpringBoot下delete请求不可用There was an unexpected error (type=Method Not Allowed, status=405).

1、页面提交delete请求,出现Whitelabel Error Page错误

<button th:attr="aaa@qq.com{/emp/}+${emp.id}" class="btn btn-sm btn-danger deleteBtn">删除</button>

解决SpringBoot下delete请求不可用There was an unexpected error (type=Method Not Allowed, status=405).

<form id="deleteEmpForm"  method="post">
	<input type="hidden" name="_method" value="delete"/>
</form>

解决SpringBoot下delete请求不可用There was an unexpected error (type=Method Not Allowed, status=405).

<script>
	$(".deleteBtn").click(function(){
				//删除当前员工的
			   $("#deleteEmpForm").attr("action",$(this).attr("del_uri")).submit();
				return false;
			});
</script>

解决SpringBoot下delete请求不可用There was an unexpected error (type=Method Not Allowed, status=405).
解决办法

只需要在SpringBoot配置中【application.properties】配置:

spring.mvc.hiddenmethod.filter.enabled=true

解决SpringBoot下delete请求不可用There was an unexpected error (type=Method Not Allowed, status=405).

相关标签: JavaWeb