删除员工Controller
//删除员工信息
@DeleteMapping("/emp/{id}")
public String delEmployee(@PathVariable Integer id){
dao.delete(id);
return "redirect:/emps";
}
删除员工页面
<body>
<div th:replace="commons/bar::nav"></div>
<div class="container-fluid" >
<div class="row">
<div th:replace="commons/bar::#sidebar(activeUri='employee')"></div>
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
<h2><a class="btn-success" th:href="@{/emp}">新增</a></h2>
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>Id</th>
<th>lastName</th>
<th>email</th>
<th>gender</th>
<th>department</th>
<th>birth</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr th:each="emp:${emps}">
<td>[[${emp.id}]]</td>
<td>[[${emp.lastName}]]</td>
<td>[[${emp.email}]]</td>
<td>[[${emp.gender}=='1'?'男':'女']]</td>
<td>[[${emp.department.departmentName}]]</td>
<td>[[${#dates.format(emp.birth, 'yyyy-MM-dd HH:mm')}]]</td>
<td>
<a class="btn-primary" th:href="@{/emp/}+${emp.id}">编辑</a>
<button class="btn-danger" th:attr="deluri=@{/emp/}+${emp.id}">删除</button>
</td>
</tr>
</tbody>
</table>
</div>
</main>
<!--form表单保持post请求,在增加_method-->
<form id="form" method="post">
<input type="hidden" name="_method" value="delete">
</form>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" src="asserts/js/jquery-3.2.1.slim.min.js" th:src="@{/asserts/js/jquery-3.2.1.slim.min.js}" ></script>
<script type="text/javascript" src="asserts/js/popper.min.js" th:src="@{/asserts/js/popper.min.js}"></script>
<script type="text/javascript" src="asserts/js/bootstrap.min.js" th:src="@{/asserts/js/bootstrap.min.js}"></script>
<script>
$('.btn-danger').click(function(){
$('#form').attr('action',$(this).attr('deluri')).submit();
})
</script>
</body>
本文介绍了一个基于Spring Boot的员工信息管理系统中,如何实现员工信息的删除与编辑功能。通过Controller中的DeleteMapping注解,可以实现员工信息的删除,并通过定制化的HTML页面展示员工列表,提供编辑和删除操作选项。
1298





