From cce855d41cd2705b0018f2d14d91e0ef9ec3cacb Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sun, 12 May 2024 21:29:05 +0800 Subject: [PATCH] feat: record get --- .../admin/AdminLoginController.java | 2 +- .../admin/AdminRecordController.java | 42 +++++++++++++ .../cqwu/repair/listener/CountListener.java | 32 ++++++++++ src/main/webapp/admin/record.jsp | 60 +++++++++++++++++++ src/main/webapp/admin/state.jsp | 2 +- src/main/webapp/includes/dropdown.jsp | 4 +- src/main/webapp/includes/menu.jsp | 2 +- 7 files changed, 139 insertions(+), 5 deletions(-) create mode 100644 src/main/java/cn/edu/cqwu/repair/controller/admin/AdminRecordController.java create mode 100644 src/main/java/cn/edu/cqwu/repair/listener/CountListener.java create mode 100644 src/main/webapp/admin/record.jsp diff --git a/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminLoginController.java b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminLoginController.java index c03cf96..2d520d4 100644 --- a/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminLoginController.java +++ b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminLoginController.java @@ -47,7 +47,7 @@ public class AdminLoginController { return "manage"; } if (recordService.add(user, request.getRemoteAddr()) != 0) { - session.setAttribute("adminuser", user); + session.setAttribute("adminUser", user); return "redirect:/admin/state.jsp"; } else { model.addAttribute("adminLoginMess", "* 登录异常!"); diff --git a/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminRecordController.java b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminRecordController.java new file mode 100644 index 0000000..eebdad7 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminRecordController.java @@ -0,0 +1,42 @@ +package cn.edu.cqwu.repair.controller.admin; + +import cn.edu.cqwu.repair.entity.AdminUser; +import cn.edu.cqwu.repair.service.RecordService; +import cn.edu.cqwu.repair.util.PageModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.SessionAttribute; + +import javax.servlet.http.HttpServletRequest; + +/** + * @author xtaod + */ +@Controller +public class AdminRecordController { + private final RecordService recordService; + + @Autowired + public AdminRecordController(RecordService recordService) { + this.recordService = recordService; + } + + @RequestMapping("/admin/record.do") + public String adminRecord( + @SessionAttribute AdminUser adminUser, Model model, HttpServletRequest request) { + String pageNoS = request.getParameter("pageNo"); + int pageNo = 1; + try { + pageNo = Integer.parseInt(pageNoS); + } catch (NumberFormatException ignored) { + } + PageModel pm = recordService.pageByLogname( + adminUser.getAdminName(), adminUser.getAdminGroup(), 10, pageNo + ); + pm.setPageNav("record.do"); + model.addAttribute("pm", pm); + return "/admin/record"; + } +} diff --git a/src/main/java/cn/edu/cqwu/repair/listener/CountListener.java b/src/main/java/cn/edu/cqwu/repair/listener/CountListener.java new file mode 100644 index 0000000..8a88bce --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/listener/CountListener.java @@ -0,0 +1,32 @@ +package cn.edu.cqwu.repair.listener; + +import javax.servlet.ServletContext; +import javax.servlet.annotation.WebListener; +import javax.servlet.http.HttpSessionListener; + +/** + * @author xtaod + */ +@WebListener +public class CountListener implements HttpSessionListener { + @Override + public void sessionCreated(javax.servlet.http.HttpSessionEvent se) { + ServletContext context = se.getSession().getServletContext(); + if (context.getAttribute("count") == null) { + Integer count = 1; + context.setAttribute("count", count); + } else { + Integer count = (Integer) context.getAttribute("count"); + context.setAttribute("count", count + 1); + } + } + + @Override + public void sessionDestroyed(javax.servlet.http.HttpSessionEvent se) { + ServletContext context = se.getSession().getServletContext(); + Integer count = (Integer) context.getAttribute("count"); + if (count != null) { + context.setAttribute("count", count - 1); + } + } +} diff --git a/src/main/webapp/admin/record.jsp b/src/main/webapp/admin/record.jsp new file mode 100644 index 0000000..eef8a84 --- /dev/null +++ b/src/main/webapp/admin/record.jsp @@ -0,0 +1,60 @@ +<%-- + Created by IntelliJ IDEA. + User: xtaod + Date: 2023/12/25 + Time: 19:57 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ page isELIgnored="false" %> + + + + + + + ${title} + + + + + + + +
+ <%@ include file="../includes/header.jsp" %> + +
+ +

${title}

+ + + + + + + + + + + + + + + + + + + + + + +
序号登录名用户组登录时间登录IP
${pm.fromIndex + row.index + 1}${recode.logname}${recode.usergroup}${recode.logtime}${recode.logip}
+ ${pm.pageNav} +
+
+ + diff --git a/src/main/webapp/admin/state.jsp b/src/main/webapp/admin/state.jsp index 6d25f9f..83502ea 100644 --- a/src/main/webapp/admin/state.jsp +++ b/src/main/webapp/admin/state.jsp @@ -36,7 +36,7 @@ - +