Springboot:员工管理之删除员工及退出登录(十(9))

springboot2.2.6 delete请求报错,降至2.1.11功能可用 原因未知

构建员工删除请求

com\springboot\controller\EmployeeController.java

/*删除员工信息 restful风格 restful风格*/
@DeleteMapping("/emp/{id}")
public String deleteEmp(@PathVariable("id") Integer id){
    //删除员工
    employeeDao.delete(id);
    //重定向到员工列表请求
    return "redirect:/employee";
}

在list.html增加删除员工按钮

resources\templates\list.html

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

同时定义一个delete请求(form)

<!--定义一个delete提交请求-->
<form id="deleteFrom" method="post">
	<input type="hidden" name="_method" value="delete">
</form>

点击删除按钮事件:

<!--delete请求:点击删除按钮 给form添加action属性 并把按钮的del_url复制给action-->
<script type="text/javascript">
	$(".deleteBtn").click(function () {
		$("#deleteFrom").attr("action",$(this).attr("del_url")).submit();
	})

</script>

构建退出请求

/*退出功能*/
@GetMapping("/loginout.html")
public String login(HttpSession session){
    session.invalidate();
    return "redirect:/index.html";
}

猜你喜欢

转载自www.cnblogs.com/applesnt/p/12693695.html
今日推荐