根据标签查询最新的项目和最热门的项目,默认标签为0时查询全部项目。
This commit is contained in:
@@ -4,6 +4,7 @@ import com.hellogithub.entity.userEntity;
|
|||||||
import com.hellogithub.utils.JdbcUtils;
|
import com.hellogithub.utils.JdbcUtils;
|
||||||
import org.apache.commons.dbutils.QueryRunner;
|
import org.apache.commons.dbutils.QueryRunner;
|
||||||
import org.apache.commons.dbutils.handlers.BeanHandler;
|
import org.apache.commons.dbutils.handlers.BeanHandler;
|
||||||
|
import org.apache.commons.dbutils.handlers.ScalarHandler;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
||||||
@@ -170,4 +171,19 @@ public class UserDao {
|
|||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long retUserNum(){
|
||||||
|
Long count;
|
||||||
|
try {
|
||||||
|
Connection conn = JdbcUtils.getConnection();
|
||||||
|
ScalarHandler handler=new ScalarHandler<Integer>();
|
||||||
|
QueryRunner runner = new QueryRunner();
|
||||||
|
String sql = "select count(*) from user";
|
||||||
|
count =(Long) runner.query( conn,sql,new ScalarHandler());
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ import com.hellogithub.utils.JdbcUtils;
|
|||||||
import org.apache.commons.dbutils.QueryRunner;
|
import org.apache.commons.dbutils.QueryRunner;
|
||||||
import org.apache.commons.dbutils.handlers.BeanHandler;
|
import org.apache.commons.dbutils.handlers.BeanHandler;
|
||||||
import org.apache.commons.dbutils.handlers.BeanListHandler;
|
import org.apache.commons.dbutils.handlers.BeanListHandler;
|
||||||
|
import org.apache.commons.dbutils.handlers.ScalarHandler;
|
||||||
|
|
||||||
|
import java.lang.ref.PhantomReference;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -59,7 +62,7 @@ public class projectDao {
|
|||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql = "select count(1) from project";
|
String sql = "select count(*) from project";
|
||||||
count = runner.query(conn, sql, new BeanHandler<>(Integer.class));
|
count = runner.query(conn, sql, new BeanHandler<>(Integer.class));
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -98,6 +101,11 @@ public class projectDao {
|
|||||||
}
|
}
|
||||||
return projectEntityList;
|
return projectEntityList;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 按照分类检索项目
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
public List<projectEntity> retSelcetByCate(int cateid){
|
public List<projectEntity> retSelcetByCate(int cateid){
|
||||||
List<projectEntity> projectEntityList;
|
List<projectEntity> projectEntityList;
|
||||||
try {
|
try {
|
||||||
@@ -110,7 +118,11 @@ public class projectDao {
|
|||||||
}
|
}
|
||||||
return projectEntityList;
|
return projectEntityList;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 按照分类检索最热门项目
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
public List<projectEntity> retSelcetByStartNum(int cateid){
|
public List<projectEntity> retSelcetByStartNum(int cateid){
|
||||||
List<projectEntity> projectEntityList;
|
List<projectEntity> projectEntityList;
|
||||||
try {
|
try {
|
||||||
@@ -123,6 +135,11 @@ public class projectDao {
|
|||||||
}
|
}
|
||||||
return projectEntityList;
|
return projectEntityList;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 检索所有最热门的项目
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
public List<projectEntity> retMostStar(){
|
public List<projectEntity> retMostStar(){
|
||||||
List<projectEntity> projectEntityList;
|
List<projectEntity> projectEntityList;
|
||||||
try {
|
try {
|
||||||
@@ -136,4 +153,7 @@ public class projectDao {
|
|||||||
return projectEntityList;
|
return projectEntityList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,4 +47,10 @@ 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 Long retUserNums(){return userDao.retUserNum();}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ import com.hellogithub.dao.UserDao;
|
|||||||
import com.hellogithub.dao.projectDao;
|
import com.hellogithub.dao.projectDao;
|
||||||
import com.hellogithub.entity.projectEntity;
|
import com.hellogithub.entity.projectEntity;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.sql.Array;
|
||||||
import java.util.Iterator;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class projectService {
|
public class projectService {
|
||||||
|
|
||||||
@@ -109,6 +107,9 @@ public class projectService {
|
|||||||
}
|
}
|
||||||
return projectEntityList;
|
return projectEntityList;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 返回根据标签查询最热门的项目
|
||||||
|
* */
|
||||||
public List<projectEntity> retSelcetByStar(int cate){
|
public List<projectEntity> retSelcetByStar(int cate){
|
||||||
if (cate==0){
|
if (cate==0){
|
||||||
return projectDao.retMostStar();
|
return projectDao.retMostStar();
|
||||||
@@ -118,4 +119,5 @@ public class projectService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,11 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
/**
|
||||||
|
* 根据标签查询最热门的项目
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
@WebServlet("/selectMostStar")
|
@WebServlet("/selectMostStar")
|
||||||
public class selectMostStarServlet extends HttpServlet {
|
public class selectMostStarServlet extends HttpServlet {
|
||||||
private projectService projectService=new projectService();
|
private projectService projectService=new projectService();
|
||||||
@@ -38,7 +42,7 @@ public class selectMostStarServlet extends HttpServlet {
|
|||||||
resp.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
|
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");
|
resp.setContentType("application/json;charset=UTF-8");
|
||||||
|
|
||||||
String cate = req.getParameter("xxxxxxx");
|
String cate = req.getParameter("cate");
|
||||||
PrintWriter writer = resp.getWriter();
|
PrintWriter writer = resp.getWriter();
|
||||||
String jsonString = JSONObject.toJSONString(projectService.retSelcetByStar(Integer.valueOf(cate)));
|
String jsonString = JSONObject.toJSONString(projectService.retSelcetByStar(Integer.valueOf(cate)));
|
||||||
writer.println(jsonString);
|
writer.println(jsonString);
|
||||||
|
|||||||
55
src/com/hellogithub/servlet/userNumServlet.java
Normal file
55
src/com/hellogithub/servlet/userNumServlet.java
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package com.hellogithub.servlet;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.hellogithub.dao.UserDao;
|
||||||
|
import jakarta.servlet.ServletConfig;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.annotation.WebServlet;
|
||||||
|
import jakarta.servlet.http.HttpServlet;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
/**
|
||||||
|
* 返回数据库中用户的总人数
|
||||||
|
* */
|
||||||
|
@WebServlet("/userNum")
|
||||||
|
public class userNumServlet extends HttpServlet {
|
||||||
|
UserDao userDao = new UserDao();
|
||||||
|
@Override
|
||||||
|
public void init(ServletConfig config) throws ServletException {
|
||||||
|
super.init(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 str= "num:"+ userDao.retUserNum();
|
||||||
|
String jsonString = JSONObject.toJSONString(str);
|
||||||
|
writer.println(jsonString);
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
super.service(req, resp);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user