移除教师信息功能可用

Signed-off-by: Chenx221 <chenx221@yandex.com>
This commit is contained in:
Chenx221 2023-06-17 10:56:28 +08:00
parent f023952f0b
commit 278b08e1e9
12 changed files with 152 additions and 179 deletions

View File

@ -77,6 +77,10 @@
WHERE id = #{id}; WHERE id = #{id};
</update> </update>
<update id="deleteTeacher" parameterType="int">
UPDATE teacher
SET removed = 1
WHERE id = #{id};
</update>
</mapper> </mapper>

View File

@ -177,7 +177,7 @@
data-mdb-placement="top" title="编辑"> data-mdb-placement="top" title="编辑">
<i class="fas fa-pencil"></i> <i class="fas fa-pencil"></i>
</button> </button>
<button type="button" class="btn btn-danger" data-mdb-toggle="tooltip" <button type="button" class="btn btn-danger deleteButton" data-mdb-toggle="tooltip"
data-mdb-placement="top" title="删除"> data-mdb-placement="top" title="删除">
<i class="fas fa-trash"></i> <i class="fas fa-trash"></i>
</button> </button>
@ -386,7 +386,7 @@
</div> </div>
<div class="tab-pane fade" id="ex1-tabs-3" role="tabpanel" aria-labelledby="ex1-tab-3"> <div class="tab-pane fade" id="ex1-tabs-3" role="tabpanel" aria-labelledby="ex1-tab-3">
<div class="card-body" style="min-width: 175px"> <div class="card-body" style="min-width: 175px">
<form action="del" method="post"> <form action="del" method="post" id="delform">
<div class="row mb-2"> <div class="row mb-2">
<div class="col-12"> <div class="col-12">
<div class="form-outline"> <div class="form-outline">
@ -578,99 +578,70 @@
method: 'POST', // 根据您的需求选择请求方法 (POST, GET, etc.) method: 'POST', // 根据您的需求选择请求方法 (POST, GET, etc.)
data: $('#modform').serialize(), data: $('#modform').serialize(),
success: function (response) { success: function (response) {
$('#de_message').text(response); success(response)
$('#de_button').on('click', function () {
reloadka("reload");
});
$('#exampleModal3').modal('show').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理
reloadka("reload");
});
}, },
error: function (xhr, status, error) { error: function (xhr, status, error) {
if (xhr.status === 400) { error(xhr,status,error)
$('#de_message').text(xhr.responseText);
$('#de_button').on('click', function () {
reloadka("close");
});
$('#exampleModal3').modal('show');
} else {
console.log('请求失败:', error);
alert('请求请求失败,请重试');
}
} }
}); });
}); });
$('#delform').on('submit', function (event) {
event.preventDefault();
if (confirm('确定要删除吗?')) {
$.ajax({
url: 'del',
method: 'POST',
data: $('#delform').serialize(),
success: function (response) {
success(response)
},
error: function (xhr, status, error) {
error(xhr,status,error)
}
});
}
});
$('.deleteButton').on('click', function () {
if (confirm('确定要删除吗?')) {
var id = $(this).closest('tr').find('td:first').text();
$.ajax({
url: 'del',
method: 'POST',
data: { id: id }, // 发送ID值到后端
success: function (response) {
success(response)
},
error: function (xhr, status, error) {
error(xhr,status,error)
}
});
}
});
}); });
// //使用ajax在后台发送post禁用/启用用户请求 function success(response){
// function userdisabled(id) { $('#de_message').text(response);
// //btn-danger $('#de_button').on('click', function () {
// $.ajax({ reloadka("reload");
// url: 'userdisabled', });
// type: 'post', $('#exampleModal3').modal('show').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理
// data: { reloadka("reload");
// id: id });
// }, }
// success: function (data) { function error(xhr,status,error){
// if (data.status === 'success') { if (xhr.status === 400) {
// $('#de_message').text(data.message); $('#de_message').text(xhr.responseText);
// $('#de_button').on('click', function () { $('#de_button').on('click', function () {
// reloadka("reload"); reloadka("close");
// }); });
// $('#exampleModal3').modal('show'); $('#exampleModal3').modal('show');
// $('#exampleModal3').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 } else {
// reloadka("reload"); console.log('请求失败:', error);
// }); alert('请求请求失败,请重试');
// } else { }
// $('#de_message').text(data.message); }
// $('#de_button').on('click', function () {
// reloadka("close");
// });
// $('#exampleModal3').modal('show');
// }
// },
// error: function (xhr, status, error) {
// // 处理请求失败的逻辑
// console.log('请求失败:', error);
// alert('请求请求失败,请重试');
// }
// });
// }
//
// function userenabled(id) {
// $.ajax({
// url: 'userenabled',
// type: 'post',
// data: {
// id: id
// },
// success: function (data) {
// if (data.status === 'success') {
// $('#de_message').text(data.message);
// $('#de_button').on('click', function () {
// reloadka("reload");
// });
// $('#exampleModal3').modal('show');
// $('#exampleModal3').on('hidden.bs.modal', function () {
// reloadka("reload");
// });
// } else {
// $('#de_message').text(data.message);
// $('#de_button').on('click', function () {
// reloadka("close");
// });
// $('#exampleModal3').modal('show');
// }
// },
// error: function (xhr, status, error) {
// // 处理请求失败的逻辑
// console.log('请求失败:', error);
// alert('请求请求失败,请重试');
// }
// });
// }
//
//处理成功/失败后的刷新页面/关闭模态框操作 //处理成功/失败后的刷新页面/关闭模态框操作
function reloadka(action) { function reloadka(action) {
if (action === 'reload') { if (action === 'reload') {

View File

@ -23,12 +23,10 @@ import java.util.List;
@RequestMapping("/teacher") @RequestMapping("/teacher")
public class TeacherController { public class TeacherController {
private final TeacherService teacherService; private final TeacherService teacherService;
private final CourseService courseService;
@Autowired @Autowired
public TeacherController(TeacherService teacherService, CourseService courseService) { public TeacherController(TeacherService teacherService) {
this.teacherService = teacherService; this.teacherService = teacherService;
this.courseService = courseService;
} }
@GetMapping("/manage") @GetMapping("/manage")
@ -150,4 +148,18 @@ public class TeacherController {
return ResponseEntity.ok("修改成功"); return ResponseEntity.ok("修改成功");
} }
} }
@ResponseBody
@PostMapping(value = "/del",produces = "text/plain;charset=UTF-8")
public ResponseEntity<String> postDelete(@RequestParam(value = "id") int id) {
if (id <= 0) {
return ResponseEntity.badRequest().body("ID非法");
}
int status_code = teacherService.deleteTeacher(id);
if (status_code == 0) {
return ResponseEntity.badRequest().body("删除失败");
} else {
return ResponseEntity.ok("删除成功");
}
}
} }

View File

@ -13,4 +13,6 @@ public interface TeacherDao {
int updateTeacher(Teacher teacher); int updateTeacher(Teacher teacher);
int deleteTeacher(int id);
} }

View File

@ -32,4 +32,9 @@ public class TeacherDaoImpl implements TeacherDao {
return sqlSession.update("updateTeacher", teacher); return sqlSession.update("updateTeacher", teacher);
} }
@Override
public int deleteTeacher(int id) {
return sqlSession.update("deleteTeacher", id);
}
} }

View File

@ -26,4 +26,8 @@ public class TeacherService {
public int updateTeacher(Teacher teacher) { public int updateTeacher(Teacher teacher) {
return teacherDao.updateTeacher(teacher); return teacherDao.updateTeacher(teacher);
} }
public int deleteTeacher(int id) {
return teacherDao.deleteTeacher(id);
}
} }

View File

@ -77,6 +77,10 @@
WHERE id = #{id}; WHERE id = #{id};
</update> </update>
<update id="deleteTeacher" parameterType="int">
UPDATE teacher
SET removed = 1
WHERE id = #{id};
</update>
</mapper> </mapper>

View File

@ -177,7 +177,7 @@
data-mdb-placement="top" title="编辑"> data-mdb-placement="top" title="编辑">
<i class="fas fa-pencil"></i> <i class="fas fa-pencil"></i>
</button> </button>
<button type="button" class="btn btn-danger" data-mdb-toggle="tooltip" <button type="button" class="btn btn-danger deleteButton" data-mdb-toggle="tooltip"
data-mdb-placement="top" title="删除"> data-mdb-placement="top" title="删除">
<i class="fas fa-trash"></i> <i class="fas fa-trash"></i>
</button> </button>
@ -386,7 +386,7 @@
</div> </div>
<div class="tab-pane fade" id="ex1-tabs-3" role="tabpanel" aria-labelledby="ex1-tab-3"> <div class="tab-pane fade" id="ex1-tabs-3" role="tabpanel" aria-labelledby="ex1-tab-3">
<div class="card-body" style="min-width: 175px"> <div class="card-body" style="min-width: 175px">
<form action="del" method="post"> <form action="del" method="post" id="delform">
<div class="row mb-2"> <div class="row mb-2">
<div class="col-12"> <div class="col-12">
<div class="form-outline"> <div class="form-outline">
@ -578,99 +578,70 @@
method: 'POST', // 根据您的需求选择请求方法 (POST, GET, etc.) method: 'POST', // 根据您的需求选择请求方法 (POST, GET, etc.)
data: $('#modform').serialize(), data: $('#modform').serialize(),
success: function (response) { success: function (response) {
$('#de_message').text(response); success(response)
$('#de_button').on('click', function () {
reloadka("reload");
});
$('#exampleModal3').modal('show').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理
reloadka("reload");
});
}, },
error: function (xhr, status, error) { error: function (xhr, status, error) {
if (xhr.status === 400) { error(xhr,status,error)
$('#de_message').text(xhr.responseText);
$('#de_button').on('click', function () {
reloadka("close");
});
$('#exampleModal3').modal('show');
} else {
console.log('请求失败:', error);
alert('请求请求失败,请重试');
}
} }
}); });
}); });
$('#delform').on('submit', function (event) {
event.preventDefault();
if (confirm('确定要删除吗?')) {
$.ajax({
url: 'del',
method: 'POST',
data: $('#delform').serialize(),
success: function (response) {
success(response)
},
error: function (xhr, status, error) {
error(xhr,status,error)
}
});
}
});
$('.deleteButton').on('click', function () {
if (confirm('确定要删除吗?')) {
var id = $(this).closest('tr').find('td:first').text();
$.ajax({
url: 'del',
method: 'POST',
data: { id: id }, // 发送ID值到后端
success: function (response) {
success(response)
},
error: function (xhr, status, error) {
error(xhr,status,error)
}
});
}
});
}); });
// //使用ajax在后台发送post禁用/启用用户请求 function success(response){
// function userdisabled(id) { $('#de_message').text(response);
// //btn-danger $('#de_button').on('click', function () {
// $.ajax({ reloadka("reload");
// url: 'userdisabled', });
// type: 'post', $('#exampleModal3').modal('show').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理
// data: { reloadka("reload");
// id: id });
// }, }
// success: function (data) { function error(xhr,status,error){
// if (data.status === 'success') { if (xhr.status === 400) {
// $('#de_message').text(data.message); $('#de_message').text(xhr.responseText);
// $('#de_button').on('click', function () { $('#de_button').on('click', function () {
// reloadka("reload"); reloadka("close");
// }); });
// $('#exampleModal3').modal('show'); $('#exampleModal3').modal('show');
// $('#exampleModal3').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 } else {
// reloadka("reload"); console.log('请求失败:', error);
// }); alert('请求请求失败,请重试');
// } else { }
// $('#de_message').text(data.message); }
// $('#de_button').on('click', function () {
// reloadka("close");
// });
// $('#exampleModal3').modal('show');
// }
// },
// error: function (xhr, status, error) {
// // 处理请求失败的逻辑
// console.log('请求失败:', error);
// alert('请求请求失败,请重试');
// }
// });
// }
//
// function userenabled(id) {
// $.ajax({
// url: 'userenabled',
// type: 'post',
// data: {
// id: id
// },
// success: function (data) {
// if (data.status === 'success') {
// $('#de_message').text(data.message);
// $('#de_button').on('click', function () {
// reloadka("reload");
// });
// $('#exampleModal3').modal('show');
// $('#exampleModal3').on('hidden.bs.modal', function () {
// reloadka("reload");
// });
// } else {
// $('#de_message').text(data.message);
// $('#de_button').on('click', function () {
// reloadka("close");
// });
// $('#exampleModal3').modal('show');
// }
// },
// error: function (xhr, status, error) {
// // 处理请求失败的逻辑
// console.log('请求失败:', error);
// alert('请求请求失败,请重试');
// }
// });
// }
//
//处理成功/失败后的刷新页面/关闭模态框操作 //处理成功/失败后的刷新页面/关闭模态框操作
function reloadka(action) { function reloadka(action) {
if (action === 'reload') { if (action === 'reload') {