From 278b08e1e90efc14b645d0de368c77116f1e3c58 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Sat, 17 Jun 2023 10:56:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=95=99=E5=B8=88=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=8A=9F=E8=83=BD=E5=8F=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chenx221 --- .../controller/TeacherController.class | Bin 6717 -> 7132 bytes .../cyou/chenx221/mapper/TeacherDao.class | Bin 546 -> 577 bytes .../chenx221/mapper/impl/TeacherDaoImpl.class | Bin 1476 -> 1661 bytes .../chenx221/service/TeacherService.class | Bin 1165 -> 1284 bytes .../WEB-INF/classes/mapper/TeacherMapper.xml | 6 +- .../WEB-INF/views/teachermanage.jsp | 145 +++++++----------- .../controller/TeacherController.java | 18 ++- .../java/cyou/chenx221/mapper/TeacherDao.java | 2 + .../chenx221/mapper/impl/TeacherDaoImpl.java | 5 + .../cyou/chenx221/service/TeacherService.java | 4 + .../main/resources/mapper/TeacherMapper.xml | 6 +- project2/web/WEB-INF/views/teachermanage.jsp | 145 +++++++----------- 12 files changed, 152 insertions(+), 179 deletions(-) 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 cba61f9536f50a3aa9f5f103665cbd57cdad4ae8..e0722e857453e6053198edb7cd47f1c4a2bf512c 100644 GIT binary patch delta 1458 zcmZ{kSxi$w6o&t~v~;1iWfM>yAYuT8Xp9R6HO37w#wQbv#6%)hA51jhi!l*=(4g_b zcwf}SHITSV1r-+*7esMGR6uc85ES=a>hjODT&lr`d;8CSXU?4Sotah*zdy=e_v^%I z0Aq#l+Nav4*)b4%9N3F}0)6s4i#^LcGd;QU7kTmpOexu^*;X77aI_Zh=-6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?l;LIScUo8GZ%MqKE4#^SH4?beS_oU57lgo;!e6d4^x9;yB0M zQq@vf5QktyRJ!d1SUO6TSu5lmoPg{cy-umGF*#5G)J z>g`lFlse2%hH;Y~#J)m$R3o^>%cN)7=~0bR5gpZSm7Y|0sQk(s;|W5dm!lU{YMd&x zS4qi6LqxPGHetlYX58g+8J3F{+{1nHX%NkLfQOiaRiY7(sC3bUm6*U|l#2~mibJG1 zw?NZzdg=6;!%?f_35m&0c&d0tsU}$&o98n;S6p8xuH70J9fBj0=t~=;Yg#sD1>7}9 zOPQ}+bI;)HrLSGL$Q+aA|1afA?Hn&Mi4Sk^mY7rK!G+T->aMEo`(;hC>xbi zHY%rVRPRVxc6=VPMDjn8hb)YrdIImM0@#RSm?G~WGHf%+JH!Tw;sZ};q#LiUap@-T zk#~6TNl~t*`po$(>1l`b7e#uvUqNA8CmEfKvLxTBqO9GW1!!Ak@4Id>ATPeEfWE1K a3%7m;NVyaUSOUC^|6{(Eb4pegPl= 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 97665ee50c7dfe6a4982fe4c32a5483ecc0993ff..c3e6b2bcbbf8362f1733909b546e3124c1350e6f 100644 GIT binary patch delta 80 zcmZ3)a*&1V)W2Q(7#J9A8ALX6r85firljVimZXNHCMIX37BMogXn0P}Wh`T4nf!!N eLym=!fscV7sGNyG089!p2mxs}21W*91_l6Yu@9U8 delta 52 zcmX@evWSK2)W2Q(7#J9A8H6@+r87?MU@T%}p8T6pLyUomfe$Fb#K6xW0HoO%7#Rc^ F7yx(Q3D5ul 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 5ef4a35cc47ea0ab1176f04dae81ce1ec096b40a..ec1886da9aa5e3f215134e0c1e614e0639d64ac1 100644 GIT binary patch delta 567 zcmZXSJx{_=7=_Pm!D?x>kcb1sfQmw^;`bMRCdP!s#KlRcMk-kvDR?PPF+B0+SNPf>{=k6E#^)KCJG92kKZCI=^>sM z1*A$zK(v44%T^YYh(KeCF#9k}YK!WGRbo}m7YNgOhSH&uFwb=qGFJm3L@|OG7O3L> zG!~JkqR*oWEU_OVd6`wvxxzV@zriY6Y&7!;N=)x!Ou_@T{|VRPLS3}x^;!?T>dmZi zFOKyd?1+Kfu)4<@x4M{+2VjXnPThwkT@RydlIC-_*d?&d)oNG5lP&kUewNgrJ>V8d wW5;!I@3@!7@Y19bubAp0DdV1J!P{j5M5F(31`60EN#bw8Hq8v+t#RJfp18|bp`#ZTSY_1UXJW2|vj zM+prKSlQeFOn4YFE2Ve=pSr+2ViqLFiBn*-Lgl0;id7D3TgB92LM<_6&qk0iN5kFb mjPrBV%C1_NAtaO1b1DZ5#$Nm~+$g8pe`$$ja($J3zXrbBCKu2E 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 d64290b00993dd9e77aab74df3f3d497fb599d6d..3be1bc9adf991cc1ed1ed8f90d6c5ab0ec5d746b 100644 GIT binary patch delta 429 zcmaKoyGjF55Qe`wn;5d2jSxsgH@d4)6BBQRt*B+N^#K&KpkSqT64KaO?Q2*l+N^~S z;7j->;+zv9f|q8_-2U$$&RzM|_uoEVUV&YzzHma~ypKTNdR zQI*(k_nA^oC_HFou#71;sX1+Byk)gIS#dk7+N(QilD&J)(L~eu<`;ZvAfQc0HDmRf zX0yy`Oq8~#p7y%H-qFjMG2AcN0Ki=ATag z@1KJ{#`^KP-T - + + 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') {