diff --git a/src/com/hellogithub/dao/AdminDao.java b/src/com/hellogithub/dao/AdminDao.java index 9ddec83..bf3bbb6 100644 --- a/src/com/hellogithub/dao/AdminDao.java +++ b/src/com/hellogithub/dao/AdminDao.java @@ -253,4 +253,26 @@ public class AdminDao { } return num; } + + public String ret_logintime(String adminame){ + String time = null; + String sql="SELECT loginTime FROM `admin` WHERE adminName = ?;"; + PreparedStatement prep = null; + Connection conn = null; + ResultSet rs =null; + try{ + conn = JdbcUtils.getConnection(); + prep = conn.prepareStatement(sql); + prep.setString(1, adminame); + rs = prep.executeQuery(); + while(rs.next()){ + time = rs.getString(1); + } + JdbcUtils.closeConnection(prep, conn); + return time; + }catch(Exception e){ + e.printStackTrace(); + } + return time; + } } diff --git a/src/com/hellogithub/service/AdminService.java b/src/com/hellogithub/service/AdminService.java index db87b90..f6d76f5 100644 --- a/src/com/hellogithub/service/AdminService.java +++ b/src/com/hellogithub/service/AdminService.java @@ -42,4 +42,6 @@ public class AdminService { public int updateAdminDetail(int adminId , int isValid , String adminName, String adminPassword,String loginTime ) { return adminDao.updateAdminDetail(adminId,isValid,adminName,adminPassword,loginTime); } + + public String ret_logintime(String adminame){return adminDao.ret_logintime(adminame);} } diff --git a/src/com/hellogithub/servlet/systemAdmin/ret_Logintime.java b/src/com/hellogithub/servlet/systemAdmin/ret_Logintime.java new file mode 100644 index 0000000..a00b97b --- /dev/null +++ b/src/com/hellogithub/servlet/systemAdmin/ret_Logintime.java @@ -0,0 +1,43 @@ +package com.hellogithub.servlet.systemAdmin; + +import com.alibaba.fastjson.JSONObject; +import com.hellogithub.service.AdminService; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import javax.servlet.annotation.WebServlet; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.random.RandomGenerator; + +@WebServlet("/retlogintime") +public class ret_Logintime extends HttpServlet { + + private AdminService adminService = new AdminService(); + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + doPost(req,resp); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setCharacterEncoding("UTF-8"); + resp.setContentType("text/html; charset=utf-8"); + // 设置响应头允许ajax跨域访问 + String curOrigin = req.getHeader("Origin"); + resp.setHeader("Access-Control-Allow-Origin", curOrigin == null ? "true" : curOrigin); + resp.setHeader("Access-Control-Allow-Credentials", "true"); + resp.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, HEAD"); + resp.setHeader("Access-Control-Max-Age", "3600"); + resp.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With"); + resp.setContentType("application/json;charset=UTF-8"); + + PrintWriter writer = resp.getWriter(); + String adminame = req.getParameter("adminName"); + String logintime = JSONObject.toJSONString(adminService.ret_logintime(adminame)); + writer.println(logintime); + writer.close(); + } +}