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 @@