根据标签查询最新的项目和最热门的项目,默认标签为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.*;
|
||||||
|
|
||||||
@@ -171,24 +172,6 @@ public class UserDao {
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 返回用户总数
|
|
||||||
* */
|
|
||||||
public int queryUserCount(){
|
|
||||||
int num;
|
|
||||||
try {
|
|
||||||
Connection conn = JdbcUtils.getConnection();
|
|
||||||
QueryRunner runner = new QueryRunner();
|
|
||||||
String sql="select count(*) from user";
|
|
||||||
num = runner.query(conn,sql,new BeanHandler<>(Integer.class));
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long retUserNum(){
|
public Long retUserNum(){
|
||||||
Long count;
|
Long count;
|
||||||
try {
|
try {
|
||||||
|
@@ -153,4 +153,7 @@ public class projectDao {
|
|||||||
return projectEntityList;
|
return projectEntityList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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,76 +107,17 @@ public class projectService {
|
|||||||
}
|
}
|
||||||
return projectEntityList;
|
return projectEntityList;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 返回根据标签查询最热门的项目
|
||||||
|
* */
|
||||||
public List<projectEntity> retSelcetByStar(int cate){
|
public List<projectEntity> retSelcetByStar(int cate){
|
||||||
Map<Integer,String> dataMap=new HashMap<>();
|
|
||||||
dataMap.put(1,"C项目");
|
|
||||||
dataMap.put(2,"C#项目");
|
|
||||||
dataMap.put(3,"C++项目");
|
|
||||||
dataMap.put(4,"CSS项目");
|
|
||||||
dataMap.put(5,"Go项目");
|
|
||||||
dataMap.put(6,"Java项目");
|
|
||||||
dataMap.put(7,"Javascript项目");
|
|
||||||
dataMap.put(8,"Kotlin项目");
|
|
||||||
dataMap.put(9,"Obejctive-C项目");
|
|
||||||
dataMap.put(10,"PHP项目");
|
|
||||||
dataMap.put(11,"Python项目");
|
|
||||||
dataMap.put(12,"Ruby项目");
|
|
||||||
dataMap.put(13,"Rust项目");
|
|
||||||
dataMap.put(14,"Swift项目");
|
|
||||||
dataMap.put(15,"其他");
|
|
||||||
dataMap.put(16,"开源书籍");
|
|
||||||
dataMap.put(17,"机器学习");
|
|
||||||
List<projectEntity> projectEntityList;
|
|
||||||
|
|
||||||
if (cate==0){
|
if (cate==0){
|
||||||
projectEntityList =projectDao.retMostStar();
|
return projectDao.retMostStar();
|
||||||
for(int i =0;i<projectEntityList.size();i++)
|
|
||||||
{
|
|
||||||
|
|
||||||
projectEntity projectEntity = projectEntityList.get(i);
|
|
||||||
projectEntity.setCategoryName(dataMap.get(projectEntity.getCategoryId()));
|
|
||||||
|
|
||||||
}
|
|
||||||
}else {
|
}else {
|
||||||
projectEntityList =projectDao.retSelcetByStartNum(cate);
|
return projectDao.retSelcetByStartNum(cate);
|
||||||
|
|
||||||
for(int i =0;i<projectEntityList.size();i++)
|
|
||||||
{
|
|
||||||
|
|
||||||
projectEntity projectEntity = projectEntityList.get(i);
|
|
||||||
projectEntity.setCategoryName(dataMap.get(projectEntity.getCategoryId()));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return projectEntityList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<projectEntity> selectByInput(String str){
|
|
||||||
Map<Integer,String> dataMap=new HashMap<>();
|
|
||||||
dataMap.put(1,"C项目");
|
|
||||||
dataMap.put(2,"C#项目");
|
|
||||||
dataMap.put(3,"C++项目");
|
|
||||||
dataMap.put(4,"CSS项目");
|
|
||||||
dataMap.put(5,"Go项目");
|
|
||||||
dataMap.put(6,"Java项目");
|
|
||||||
dataMap.put(7,"Javascript项目");
|
|
||||||
dataMap.put(8,"Kotlin项目");
|
|
||||||
dataMap.put(9,"Obejctive-C项目");
|
|
||||||
dataMap.put(10,"PHP项目");
|
|
||||||
dataMap.put(11,"Python项目");
|
|
||||||
dataMap.put(12,"Ruby项目");
|
|
||||||
dataMap.put(13,"Rust项目");
|
|
||||||
dataMap.put(14,"Swift项目");
|
|
||||||
dataMap.put(15,"其他");
|
|
||||||
dataMap.put(16,"开源书籍");
|
|
||||||
dataMap.put(17,"机器学习");
|
|
||||||
List<projectEntity> projectEntityList = projectDao.selectByInput(str);
|
|
||||||
for(int i =0;i<projectEntityList.size();i++)
|
|
||||||
{
|
|
||||||
projectEntity projectEntity = projectEntityList.get(i);
|
|
||||||
projectEntity.setCategoryName(dataMap.get(projectEntity.getCategoryId()));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return projectEntityList;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,73 +0,0 @@
|
|||||||
package com.hellogithub.servlet;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.hellogithub.entity.projectEntity;
|
|
||||||
import com.hellogithub.service.projectService;
|
|
||||||
import jakarta.servlet.ServletConfig;
|
|
||||||
import jakarta.servlet.ServletException;
|
|
||||||
import jakarta.servlet.http.HttpServlet;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class selectByInputServlet extends HttpServlet {
|
|
||||||
private com.hellogithub.service.projectService projectService=new projectService();
|
|
||||||
@Override
|
|
||||||
public void init(ServletConfig config) throws ServletException {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 = req.getParameter("xxxxx");
|
|
||||||
List<projectEntity> projectEntityList = projectService.selectByInput(str);
|
|
||||||
if(projectEntityList.size() == 0 ){
|
|
||||||
setResultError("查询结果为空",writer);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
String jsonString = JSONObject.toJSONString(projectEntityList);
|
|
||||||
setResultOK("success",writer);
|
|
||||||
writer.println(jsonString);
|
|
||||||
writer.close();
|
|
||||||
setResultOK("success",writer);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
public void setResult(Integer code, String msg, PrintWriter writer) {
|
|
||||||
HashMap<String, Object> result = new HashMap<>();
|
|
||||||
result.put("code", code);
|
|
||||||
result.put("msg", msg);
|
|
||||||
String jsonString = JSONObject.toJSONString(result);
|
|
||||||
writer.println(jsonString);
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResultError(String msg, PrintWriter writer) {
|
|
||||||
setResult(500, msg, writer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResultOK(String msg, PrintWriter writer) {
|
|
||||||
setResult(200, msg, writer);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -42,7 +42,7 @@ public class selectLastByCateServlet 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("num");
|
String cate = req.getParameter("cate");
|
||||||
PrintWriter writer = resp.getWriter();
|
PrintWriter writer = resp.getWriter();
|
||||||
String jsonString = JSONObject.toJSONString(projectService.retLatestProject(Integer.valueOf(cate)));
|
String jsonString = JSONObject.toJSONString(projectService.retLatestProject(Integer.valueOf(cate)));
|
||||||
writer.println(jsonString);
|
writer.println(jsonString);
|
||||||
|
@@ -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,8 +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("num");
|
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);
|
||||||
|
@@ -5,9 +5,6 @@ import com.hellogithub.dao.UserDao;
|
|||||||
import jakarta.servlet.ServletConfig;
|
import jakarta.servlet.ServletConfig;
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.annotation.WebServlet;
|
import jakarta.servlet.annotation.WebServlet;
|
||||||
import com.hellogithub.service.UserService;
|
|
||||||
import jakarta.servlet.ServletConfig;
|
|
||||||
import jakarta.servlet.ServletException;
|
|
||||||
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;
|
||||||
@@ -23,20 +20,12 @@ public class userNumServlet extends HttpServlet {
|
|||||||
@Override
|
@Override
|
||||||
public void init(ServletConfig config) throws ServletException {
|
public void init(ServletConfig config) throws ServletException {
|
||||||
super.init(config);
|
super.init(config);
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class userNumServlet extends HttpServlet {
|
|
||||||
private UserService userService = new UserService();
|
|
||||||
@Override
|
|
||||||
public void init(ServletConfig config) throws ServletException {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
|
||||||
doPost(req,resp);
|
doPost(req,resp);
|
||||||
doPost(req, resp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,33 +51,5 @@ public class userNumServlet extends HttpServlet {
|
|||||||
@Override
|
@Override
|
||||||
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
super.service(req, resp);
|
super.service(req, resp);
|
||||||
int num = userService.queryUserCount();
|
|
||||||
String str= "num:"+num ;
|
|
||||||
String jsonString = JSONObject.toJSONString(str);
|
|
||||||
writer.println(jsonString);
|
|
||||||
if(num == 0)
|
|
||||||
{
|
|
||||||
setResultError("用户总数为空",writer);
|
|
||||||
}else{
|
|
||||||
setResultOK("success",writer);
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
public void setResult(Integer code, String msg, PrintWriter writer) {
|
|
||||||
HashMap<String, Object> result = new HashMap<>();
|
|
||||||
result.put("code", code);
|
|
||||||
result.put("msg", msg);
|
|
||||||
String jsonString = JSONObject.toJSONString(result);
|
|
||||||
writer.println(jsonString);
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResultError(String msg, PrintWriter writer) {
|
|
||||||
setResult(500, msg, writer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResultOK(String msg, PrintWriter writer) {
|
|
||||||
setResult(200, msg, writer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
driverClass=com.mysql.cj.jdbc.Driver
|
driverClass=com.mysql.cj.jdbc.Driver
|
||||||
url=jdbc:mysql://127.0.0.1:3306/hellogithub?serverTimezone=GMT%2B8
|
url=jdbc:mysql://127.0.0.1:3306/hellogithub?serverTimezone=GMT%2B8
|
||||||
user=root
|
user=root
|
||||||
password=1611
|
password=123456
|
Reference in New Issue
Block a user