错误:
There was an unexpected error (type=Method Not Allowed, status=405).
Request method ‘POST’ not supported
前台代码
<button th:attr="del_uri=@{/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>
后台代码
@DeleteMapping("/emp/{id}")
public String deteleEmployee(@PathVariable("id") Integer id){
employeeDao.delete(id);
return "redirect:/emps";
}
解决方案
在springboot2中的配置文件application.properties中添加一行代码spring.mvc.hiddenmethod.filter.enabled=true