405错误,rest风格,post方法未提供,springboot2

错误:
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值