|
|
package com.inks.hb.login.controller;
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
import com.inks.hb.common.PojotoGson;
|
|
|
import com.inks.hb.logInfo.service.LogInfoServiceImpl;
|
|
|
import com.inks.hb.login.pojo.Login;
|
|
|
import com.inks.hb.login.service.LoginService;
|
|
|
import com.inks.hb.login.service.LoginServiceImpl;
|
|
|
|
|
|
import javax.servlet.annotation.WebServlet;
|
|
|
import javax.servlet.http.HttpServlet;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.io.PrintWriter;
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
@WebServlet(name = "LoginTableServlet", value = "/LoginTableServlet")
|
|
|
public class LoginTableServlet extends HttpServlet {
|
|
|
// 处理POST请求
|
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
this.doGet(request, response);
|
|
|
}
|
|
|
|
|
|
// 处理GET请求
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
|
|
|
// 设置请求编码为utf-8
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
// 设置响应编码为utf-8
|
|
|
response.setContentType("text/html;charset=utf-8");
|
|
|
// 获取响应输出流
|
|
|
PrintWriter out = response.getWriter();
|
|
|
|
|
|
// 获取请求参数
|
|
|
int page = Integer.parseInt(request.getParameter("page"));
|
|
|
int limit = Integer.parseInt(request.getParameter("limit"));
|
|
|
int make = Integer.parseInt(request.getParameter("make"));
|
|
|
|
|
|
// 创建LoginService实例
|
|
|
LoginService service = new LoginServiceImpl();
|
|
|
|
|
|
// 初始化返回结果
|
|
|
String code = "0";
|
|
|
String msg = "数据查询正常";
|
|
|
String count;
|
|
|
ArrayList list;
|
|
|
|
|
|
// 如果make参数为4,则删除对应的登录信息
|
|
|
if (make == 4) {
|
|
|
int loginId = Integer.parseInt(request.getParameter("loginId"));
|
|
|
new LogInfoServiceImpl().deleteByName(loginId);
|
|
|
service.deleteLogin(loginId);
|
|
|
}
|
|
|
|
|
|
// 查询登录信息
|
|
|
list = service.query(page, limit);
|
|
|
// 查询登录信息总数
|
|
|
count = String.valueOf(service.queryLoginNum());
|
|
|
|
|
|
|
|
|
// 将查询结果封装为PojotoGson对象
|
|
|
PojotoGson pojotoGson = new PojotoGson(code, msg, count, list);
|
|
|
// 使用Gson将PojotoGson对象转换为json字符串
|
|
|
Gson gson = new Gson();
|
|
|
out.print(gson.toJson(pojotoGson));
|
|
|
}
|
|
|
}
|