From 54d94a08feb4c926e92df82119437261d6ae2548 Mon Sep 17 00:00:00 2001 From: Qing Date: Sat, 10 Jun 2023 01:13:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=8A=9F=E8=83=BD=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/landaiqing/dao/UserDao.java | 25 ++++++ src/com/landaiqing/service/UserService.java | 8 ++ .../landaiqing/servlet/system/DeleteUser.java | 44 ++++++++++ web/System/adminManage.jsp | 7 +- web/System/messageManage.jsp | 80 ++++++++++++++++++- web/index.jsp | 14 ++-- 6 files changed, 170 insertions(+), 8 deletions(-) create mode 100644 src/com/landaiqing/servlet/system/DeleteUser.java diff --git a/src/com/landaiqing/dao/UserDao.java b/src/com/landaiqing/dao/UserDao.java index e978bf2..b355a3a 100644 --- a/src/com/landaiqing/dao/UserDao.java +++ b/src/com/landaiqing/dao/UserDao.java @@ -102,4 +102,29 @@ public class UserDao { JdbcUtils.closeConnection(null, preparedStatement, connection); } } + + /** + * 通过ID 删除 + * */ + + public int deleteUser(Integer id){ + Connection connection = null; + PreparedStatement preparedStatement = null; + try { + connection = JdbcUtils.getConnection(); + JdbcUtils.beginTransaction(connection); + preparedStatement = connection.prepareStatement("DELETE from `user` WHERE `userId` = ?;"); + preparedStatement.setInt(1,id); + Integer result = preparedStatement.executeUpdate(); + JdbcUtils.commitTransaction(connection); + return result; + + } catch (SQLException e) { + JdbcUtils.rollBackTransaction(connection); + throw new RuntimeException(e); + + } finally { + JdbcUtils.closeConnection(null, preparedStatement, connection); + } + } } diff --git a/src/com/landaiqing/service/UserService.java b/src/com/landaiqing/service/UserService.java index e158239..12e283a 100644 --- a/src/com/landaiqing/service/UserService.java +++ b/src/com/landaiqing/service/UserService.java @@ -26,4 +26,12 @@ public class UserService { public int reply(UserEntity userEntity){ return userDao.reply(userEntity); } + + /** + * 通过ID 删除 + * */ + + public int deleteUser(Integer id){ + return userDao.deleteUser(id); + } } diff --git a/src/com/landaiqing/servlet/system/DeleteUser.java b/src/com/landaiqing/servlet/system/DeleteUser.java new file mode 100644 index 0000000..6c81ee3 --- /dev/null +++ b/src/com/landaiqing/servlet/system/DeleteUser.java @@ -0,0 +1,44 @@ +package com.landaiqing.servlet.system; + +import com.landaiqing.service.UserService; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; + +@WebServlet("/deleteUser") +public class DeleteUser extends HttpServlet { + private UserService userService=new UserService(); + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String idStr = req.getParameter("id"); + if (idStr==null || idStr==""){ + req.setAttribute("errorMsg","ID的值不能为空!!!"); + req.getRequestDispatcher("./error.jsp").forward(req,resp); + return; + } + + try { + Integer id = Integer.parseInt(idStr); + int result = userService.deleteUser(id); + if (result > 0) { +// req.getRequestDispatcher("showFlight.jsp").forward(req,resp); + resp.sendRedirect("./System/index.jsp"); + + }else { + req.setAttribute("errorMsg","删除失败!!!"); + req.getRequestDispatcher("./error.jsp").forward(req,resp); + } + } catch (NumberFormatException e) { + req.setAttribute("errorMsg","类型转换异常,id 不能转换成Int类型!!!"); + req.getRequestDispatcher("./error.jsp").forward(req,resp); + e.printStackTrace(); + }catch (Exception e){ + req.setAttribute("errorMsg","系统异常!!!"); + req.getRequestDispatcher("./error.jsp").forward(req,resp); + } + } +} diff --git a/web/System/adminManage.jsp b/web/System/adminManage.jsp index 47901c5..4ce2a2e 100644 --- a/web/System/adminManage.jsp +++ b/web/System/adminManage.jsp @@ -122,7 +122,7 @@
- +
@@ -177,7 +177,7 @@
- +
@@ -252,6 +252,7 @@ layer.msg('开启成功'), { offset: '6px' } + window.location.reload(); }) } @@ -269,7 +270,9 @@ layer.msg('关闭成功'), { offset: '6px' } + window.location.reload(); }) + } function upAdateAdmin(){ diff --git a/web/System/messageManage.jsp b/web/System/messageManage.jsp index 14d4f5a..76faf9f 100644 --- a/web/System/messageManage.jsp +++ b/web/System/messageManage.jsp @@ -17,6 +17,23 @@ + + + + +
diff --git a/web/index.jsp b/web/index.jsp index c982e7c..23288f1 100644 --- a/web/index.jsp +++ b/web/index.jsp @@ -59,7 +59,7 @@
-
+
留   言   本
@@ -90,7 +90,7 @@
-
+
留言列表
@@ -226,7 +226,7 @@
-
${list.nickName}
@@ -350,8 +350,10 @@ } }).then(function (result) { //定位 span id 名称 error 修改 - console.log(result); + // console.log(result); + window.location.reload(); }) + } // 回复 function reply(userId){ @@ -368,8 +370,10 @@ } }).then(function (result) { //定位 span id 名称 error 修改 - console.log(result); + // console.log(result); + window.location.reload(); }) + } $(function () {