diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/TeacherController.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/TeacherController.class index cba61f9..e0722e8 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/TeacherController.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/TeacherController.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/TeacherDao.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/TeacherDao.class index 97665ee..c3e6b2b 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/TeacherDao.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/TeacherDao.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/TeacherDaoImpl.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/TeacherDaoImpl.class index 5ef4a35..ec1886d 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/TeacherDaoImpl.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/impl/TeacherDaoImpl.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/TeacherService.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/TeacherService.class index d64290b..3be1bc9 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/TeacherService.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/service/TeacherService.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/TeacherMapper.xml b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/TeacherMapper.xml index 9e33b33..65581cb 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/TeacherMapper.xml +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/TeacherMapper.xml @@ -77,6 +77,10 @@ WHERE id = #{id}; - + + UPDATE teacher + SET removed = 1 + WHERE id = #{id}; + \ No newline at end of file diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teachermanage.jsp b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teachermanage.jsp index 424fd52..6198e5e 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teachermanage.jsp +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teachermanage.jsp @@ -177,7 +177,7 @@ data-mdb-placement="top" title="编辑"> - @@ -386,7 +386,7 @@
-
+
@@ -578,99 +578,70 @@ method: 'POST', // 根据您的需求选择请求方法 (POST, GET, etc.) data: $('#modform').serialize(), success: function (response) { - $('#de_message').text(response); - $('#de_button').on('click', function () { - reloadka("reload"); - }); - $('#exampleModal3').modal('show').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 - reloadka("reload"); - }); + success(response) }, error: function (xhr, status, error) { - if (xhr.status === 400) { - $('#de_message').text(xhr.responseText); - $('#de_button').on('click', function () { - reloadka("close"); - }); - $('#exampleModal3').modal('show'); - } else { - console.log('请求失败:', error); - alert('请求请求失败,请重试'); - } + error(xhr,status,error) } }); }); + $('#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 userdisabled(id) { - // //btn-danger - // $.ajax({ - // url: 'userdisabled', - // 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 () { //针对点击modal外的情况的处理 - // 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 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 success(response){ + $('#de_message').text(response); + $('#de_button').on('click', function () { + reloadka("reload"); + }); + $('#exampleModal3').modal('show').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 + reloadka("reload"); + }); + } + function error(xhr,status,error){ + if (xhr.status === 400) { + $('#de_message').text(xhr.responseText); + $('#de_button').on('click', function () { + reloadka("close"); + }); + $('#exampleModal3').modal('show'); + } else { + console.log('请求失败:', error); + alert('请求请求失败,请重试'); + } + } + //处理成功/失败后的刷新页面/关闭模态框操作 function reloadka(action) { if (action === 'reload') { diff --git a/project2/src/main/java/cyou/chenx221/controller/TeacherController.java b/project2/src/main/java/cyou/chenx221/controller/TeacherController.java index 3a4519a..242bdc9 100644 --- a/project2/src/main/java/cyou/chenx221/controller/TeacherController.java +++ b/project2/src/main/java/cyou/chenx221/controller/TeacherController.java @@ -23,12 +23,10 @@ import java.util.List; @RequestMapping("/teacher") public class TeacherController { private final TeacherService teacherService; - private final CourseService courseService; @Autowired - public TeacherController(TeacherService teacherService, CourseService courseService) { + public TeacherController(TeacherService teacherService) { this.teacherService = teacherService; - this.courseService = courseService; } @GetMapping("/manage") @@ -150,4 +148,18 @@ public class TeacherController { return ResponseEntity.ok("修改成功"); } } + + @ResponseBody + @PostMapping(value = "/del",produces = "text/plain;charset=UTF-8") + public ResponseEntity 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("删除成功"); + } + } } diff --git a/project2/src/main/java/cyou/chenx221/mapper/TeacherDao.java b/project2/src/main/java/cyou/chenx221/mapper/TeacherDao.java index ecefd84..51a92be 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/TeacherDao.java +++ b/project2/src/main/java/cyou/chenx221/mapper/TeacherDao.java @@ -13,4 +13,6 @@ public interface TeacherDao { int updateTeacher(Teacher teacher); + + int deleteTeacher(int id); } diff --git a/project2/src/main/java/cyou/chenx221/mapper/impl/TeacherDaoImpl.java b/project2/src/main/java/cyou/chenx221/mapper/impl/TeacherDaoImpl.java index d5ee388..124a4a4 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/impl/TeacherDaoImpl.java +++ b/project2/src/main/java/cyou/chenx221/mapper/impl/TeacherDaoImpl.java @@ -32,4 +32,9 @@ public class TeacherDaoImpl implements TeacherDao { return sqlSession.update("updateTeacher", teacher); } + @Override + public int deleteTeacher(int id) { + return sqlSession.update("deleteTeacher", id); + } + } diff --git a/project2/src/main/java/cyou/chenx221/service/TeacherService.java b/project2/src/main/java/cyou/chenx221/service/TeacherService.java index 476f95c..45c107a 100644 --- a/project2/src/main/java/cyou/chenx221/service/TeacherService.java +++ b/project2/src/main/java/cyou/chenx221/service/TeacherService.java @@ -26,4 +26,8 @@ public class TeacherService { public int updateTeacher(Teacher teacher) { return teacherDao.updateTeacher(teacher); } + + public int deleteTeacher(int id) { + return teacherDao.deleteTeacher(id); + } } diff --git a/project2/src/main/resources/mapper/TeacherMapper.xml b/project2/src/main/resources/mapper/TeacherMapper.xml index 9e33b33..65581cb 100644 --- a/project2/src/main/resources/mapper/TeacherMapper.xml +++ b/project2/src/main/resources/mapper/TeacherMapper.xml @@ -77,6 +77,10 @@ WHERE id = #{id}; - + + UPDATE teacher + SET removed = 1 + WHERE id = #{id}; + \ No newline at end of file diff --git a/project2/web/WEB-INF/views/teachermanage.jsp b/project2/web/WEB-INF/views/teachermanage.jsp index 424fd52..6198e5e 100644 --- a/project2/web/WEB-INF/views/teachermanage.jsp +++ b/project2/web/WEB-INF/views/teachermanage.jsp @@ -177,7 +177,7 @@ data-mdb-placement="top" title="编辑"> - @@ -386,7 +386,7 @@
- +
@@ -578,99 +578,70 @@ method: 'POST', // 根据您的需求选择请求方法 (POST, GET, etc.) data: $('#modform').serialize(), success: function (response) { - $('#de_message').text(response); - $('#de_button').on('click', function () { - reloadka("reload"); - }); - $('#exampleModal3').modal('show').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 - reloadka("reload"); - }); + success(response) }, error: function (xhr, status, error) { - if (xhr.status === 400) { - $('#de_message').text(xhr.responseText); - $('#de_button').on('click', function () { - reloadka("close"); - }); - $('#exampleModal3').modal('show'); - } else { - console.log('请求失败:', error); - alert('请求请求失败,请重试'); - } + error(xhr,status,error) } }); }); + $('#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 userdisabled(id) { - // //btn-danger - // $.ajax({ - // url: 'userdisabled', - // 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 () { //针对点击modal外的情况的处理 - // 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 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 success(response){ + $('#de_message').text(response); + $('#de_button').on('click', function () { + reloadka("reload"); + }); + $('#exampleModal3').modal('show').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 + reloadka("reload"); + }); + } + function error(xhr,status,error){ + if (xhr.status === 400) { + $('#de_message').text(xhr.responseText); + $('#de_button').on('click', function () { + reloadka("close"); + }); + $('#exampleModal3').modal('show'); + } else { + console.log('请求失败:', error); + alert('请求请求失败,请重试'); + } + } + //处理成功/失败后的刷新页面/关闭模态框操作 function reloadka(action) { if (action === 'reload') {