查询用户总数进行修改
This commit is contained in:
@@ -175,13 +175,15 @@ public class UserDao {
|
|||||||
*
|
*
|
||||||
* 返回用户总数
|
* 返回用户总数
|
||||||
* */
|
* */
|
||||||
public int queryUserCount(){
|
public long queryUserCount(){
|
||||||
int num;
|
userEntity userEntity;
|
||||||
|
long num;
|
||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="select count(*) from user";
|
String sql="select count(*) as num from user";
|
||||||
num = runner.query(conn,sql,new BeanHandler<>(Integer.class));
|
userEntity = runner.query(conn,sql,new BeanHandler<>(userEntity.class));
|
||||||
|
num = userEntity.getNum();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@@ -117,4 +117,13 @@ public class userEntity {
|
|||||||
", searchHistory='" + searchHistory + '\'' +
|
", searchHistory='" + searchHistory + '\'' +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
long num;
|
||||||
|
|
||||||
|
public long getNum() {
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNum(long num) {
|
||||||
|
this.num = num;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -47,5 +47,5 @@ public class UserService {
|
|||||||
* @param name
|
* @param name
|
||||||
* */
|
* */
|
||||||
public int dedleteAllLabel(String name){return userDao.dedleteAllLabel(name);}
|
public int dedleteAllLabel(String name){return userDao.dedleteAllLabel(name);}
|
||||||
public int queryUserCount(){return userDao.queryUserCount();}
|
public long queryUserCount(){return userDao.queryUserCount();}
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
package com.hellogithub.servlet;
|
package com.hellogithub.servlet;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.hellogithub.dao.UserDao;
|
||||||
import com.hellogithub.service.UserService;
|
import com.hellogithub.service.UserService;
|
||||||
import jakarta.servlet.ServletConfig;
|
import jakarta.servlet.ServletConfig;
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.annotation.WebServlet;
|
||||||
import jakarta.servlet.http.HttpServlet;
|
import jakarta.servlet.http.HttpServlet;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
@@ -11,7 +13,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@WebServlet("/userNum")
|
||||||
public class userNumServlet extends HttpServlet {
|
public class userNumServlet extends HttpServlet {
|
||||||
private UserService userService = new UserService();
|
private UserService userService = new UserService();
|
||||||
@Override
|
@Override
|
||||||
@@ -38,7 +40,7 @@ public class userNumServlet extends HttpServlet {
|
|||||||
resp.setContentType("application/json;charset=UTF-8");
|
resp.setContentType("application/json;charset=UTF-8");
|
||||||
|
|
||||||
PrintWriter writer = resp.getWriter();
|
PrintWriter writer = resp.getWriter();
|
||||||
int num = userService.queryUserCount();
|
long num = userService.queryUserCount();
|
||||||
String str= "num:"+num ;
|
String str= "num:"+num ;
|
||||||
String jsonString = JSONObject.toJSONString(str);
|
String jsonString = JSONObject.toJSONString(str);
|
||||||
writer.println(jsonString);
|
writer.println(jsonString);
|
||||||
|
Reference in New Issue
Block a user