删除学生信息
前端
index.html
<button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">
<i class="layui-icon layui-icon-delete"></i>删除
</button>lay-event="delete" 为删除按钮监听事件
index.js
javascript
function tool(table) {
table.on('tool(layFilter)', function (obj) {
let data = obj.data;
// ......
if ('delete' === obj.event) {
let msg = '确定删除学生【' + data.name + '】的信息吗?';
layer.confirm('<div style="color: #ff000c">' + msg + '</div>', {
icon: 3,
title: '系统提示!'
}, function () {
$.ajax({
type: 'delete',
url: path + '/' + data.id,
success: function (res) {
if (res.success) {
reloadTableData(table); // 删除成功, 刷新表格
layer.msg(res.msg, {icon: 1, time: 1500});
} else {
layer.msg(res.msg, {icon: 1, time: 1500});
}
}
})
});
}
})
}后端
StudentInfoController
@DeleteMapping("/{id}")
@ResponseBody
public ServerResponse<StudentInfoVO> deleteStudentInfo(@PathVariable("id") String id) throws Exception {
studentInfoService.deleteStudentInfoById(id);
return ServerResponse.ok();
}IStudentInfoService
void deleteStudentInfoById(String id) throws Exception;StudentInfoServiceImpl
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteStudentInfoById(String id) throws Exception {
studentInfoMapper.deleteStudentInfoById(id);
}IStudentInfoMapper
void deleteStudentInfoById(String id);StudentInfoMapper.xml
xml
<delete id="deleteStudentInfoById" parameterType="java.lang.String">
DELETE
FROM fly_student_info
WHERE id = #{id}
</delete>
剑鸣秋朔