本文介绍,前端页面的多个选择框被勾选,然后被一键删除的操作
前端页面
<!--表格-->
<form action="#" id="form11" method="post" style="padding-left: 20px;padding-right: 20px" th:action="@{/deleteBeSelect}">
<table border="1" class="table table-bordered table-hover">
<tr class="success">
<th><label for="Cb11"></label><input type="checkbox" id="Cb11"></th>
<th>序号</th>
<th>姓名</th>
<th>性别</th>
<th>身份证号</th>
<th>学号</th>
<th>学历</th>
<th>入学年份</th>
<th>科目代码</th>
<th>报考科目</th>
<th>等级</th>
<th>手机号码</th>
<th>所属院系</th>
<th>所属专业</th>
<th>所属班级</th>
<th>总学时</th>
<td>操作</td>
</tr>
<tr th:each="user:${pageList}">
<td><label>
<input type="checkbox" name="uid" th:value="${user.id}">
</label></td>
<td >[[${user.id}]]</td>
<td th:text="${user.name}"></td>
<td th:text="${user.sex}"></td>
<td th:text="${user.identityCode}"></td>
<td th:text="${user.stuNumber}"></td>
<td th:text="${user.eduBackground}"></td>
<td th:text="${user.enrollmentYear}"></td>
<td th:text="${user.subjectCode}"></td>
<td th:text="${user.examTitle}"></td>
<td th:text="${user.examLevel}"></td>
<td th:text="${user.telNumber}"></td>
<td th:text="${user.subordinateDepartments}"></td>
<td th:text="${user.major}"></td>
<td th:text="${user.classNumber}"></td>
<td >[[${user.totalHours}]]/72</td>
<td>
<a class="btn btn-default btn-sm deleteButton" href="#"
th:href="@{/user/delete/{id}(id=${user.id},pn=${pn})}">删除</a>
</td>
</tr>
</table>
</form>
/**
* 删除选中
*/
@PostMapping("/deleteBeSelect")
public String deleteBeSelect(@RequestParam("uid") String uid, Model model){
log.info("获取uid:"+uid);
String[] uId = uid.split(",");
List uidList = Arrays.asList(uId);// List<String> uidList:[30,36]
log.info(" List uidList:"+uidList);
int size = uidList.size();
log.info("size的长度:"+size);
for (int i = 0; i < uidList.size(); i++) {
Object args = uidList.get(i);
//先查询是否还有这条记录,防止表单重复提交导致的白页
String selectIfExistUid="select * from inputExcel where id=?";
List<inputExcel> query = jdbcTemplate.query(selectIfExistUid, new BeanPropertyRowMapper<inputExcel>(inputExcel.class), args);
if (query.size()>0){//当每次想要删除的数据,在数据中中还存在时才能删除
String sql = "delete from inputExcel where id=?";
jdbcTemplate.update(sql, args);
}else {
model.addAttribute("repeatDelete","你删除的数据已不存在!");
}
}
return "adminMainPage";
}