管理员登陆时间
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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);}
|
||||
}
|
||||
|
43
src/com/hellogithub/servlet/systemAdmin/ret_Logintime.java
Normal file
43
src/com/hellogithub/servlet/systemAdmin/ret_Logintime.java
Normal file
@@ -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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user