Merge remote-tracking branch 'origin/master'
This commit is contained in:
44
src/com/hellogithub/dao/categoryDao.java
Normal file
44
src/com/hellogithub/dao/categoryDao.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package com.hellogithub.dao;
|
||||
|
||||
import com.hellogithub.entity.categoryEntity;
|
||||
import com.hellogithub.entity.projectEntity;
|
||||
import com.hellogithub.utils.JdbcUtils;
|
||||
import org.apache.commons.dbutils.QueryRunner;
|
||||
import org.apache.commons.dbutils.handlers.BeanHandler;
|
||||
import org.apache.commons.dbutils.handlers.BeanListHandler;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class categoryDao {
|
||||
|
||||
//返回所有标签
|
||||
public List<categoryEntity> retLabel() {
|
||||
List<categoryEntity> categoryEntity;
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql = "select * from category ";
|
||||
categoryEntity = runner.query(conn, sql, new BeanListHandler<>(categoryEntity.class));
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return categoryEntity;
|
||||
}
|
||||
//发送Id找中文名字
|
||||
public categoryEntity retNum(int id ) {
|
||||
categoryEntity categoryEntity;
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql = "select * from category where categoryId=?";
|
||||
categoryEntity = runner.query(conn, sql, new BeanHandler<>(categoryEntity.class),id);
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return categoryEntity;
|
||||
}
|
||||
}
|
@@ -41,7 +41,7 @@ public class projectDao {
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql = "select * from project Group BY periodicals DESC limit 1";
|
||||
String sql = "select * from project Order BY periodicals DESC limit 1";
|
||||
projectEntity = runner.query(conn, sql, new BeanHandler<>(projectEntity.class));
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
@@ -54,15 +54,15 @@ public class projectDao {
|
||||
*
|
||||
*
|
||||
*/
|
||||
public int countAll() {
|
||||
int count;
|
||||
public long countAll() {
|
||||
long count;
|
||||
projectEntity p;
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql = "select count(*) as projectId from project";
|
||||
String sql = "select count(*) as num from project";
|
||||
p = runner.query(conn, sql, new BeanHandler<>(projectEntity.class));
|
||||
count = p.getProjectId();
|
||||
count = p.getNum();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -101,13 +101,13 @@ public class projectDao {
|
||||
}
|
||||
return projectEntityList;
|
||||
}
|
||||
public List<projectEntity> retSelcetByCate(int cateid){
|
||||
public List<projectEntity> retSelcetByCate(int cateid,String name){
|
||||
List<projectEntity> projectEntityList;
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql = "select * from project where projectId in (select projectId from project_category where categoryId=?)";
|
||||
projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class),cateid);
|
||||
String sql = "select * from project where projectId in (select projectId from project_category where categoryId in(select categoryId from category where categoryName = ?))";
|
||||
projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class),name);
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -115,13 +115,13 @@ public class projectDao {
|
||||
return projectEntityList;
|
||||
}
|
||||
|
||||
public List<projectEntity> retSelcetByStartNum(int cateid){
|
||||
public List<projectEntity> retSelcetByStartNum(int cateid,String name){
|
||||
List<projectEntity> projectEntityList;
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql = "select * from project where projectId in (select projectId from project_category where categoryId=?) order by lookCount desc";
|
||||
projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class),cateid);
|
||||
String sql = "select * from project where projectId in (select projectId from project_category where categoryId in(select categoryId from category where categoryName = ?)) order by lookCount desc";
|
||||
projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class),name);
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
@@ -29,4 +29,14 @@ public class categoryEntity {
|
||||
}
|
||||
|
||||
int isValid;
|
||||
|
||||
String categoryName;
|
||||
|
||||
public String getCategoryName() {
|
||||
return categoryName;
|
||||
}
|
||||
|
||||
public void setCategoryName(String categoryName) {
|
||||
this.categoryName = categoryName;
|
||||
}
|
||||
}
|
||||
|
@@ -141,4 +141,14 @@ public class projectEntity {
|
||||
public void setCategoryName(String categoryName) {
|
||||
this.categoryName = categoryName;
|
||||
}
|
||||
|
||||
long num=0;
|
||||
|
||||
public long getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(long num) {
|
||||
this.num = num;
|
||||
}
|
||||
}
|
||||
|
16
src/com/hellogithub/service/categoryService.java
Normal file
16
src/com/hellogithub/service/categoryService.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.hellogithub.service;
|
||||
|
||||
import com.hellogithub.dao.projectDao;
|
||||
import com.hellogithub.dao.categoryDao;
|
||||
import com.hellogithub.entity.categoryEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class categoryService {
|
||||
|
||||
private categoryDao categoryDao = new categoryDao();
|
||||
|
||||
public List<categoryEntity> retLabel() {return categoryDao.retLabel();}
|
||||
|
||||
public categoryEntity retNum(int id ){return categoryDao.retNum(id);}
|
||||
}
|
@@ -1,47 +1,30 @@
|
||||
package com.hellogithub.service;
|
||||
|
||||
import com.hellogithub.dao.UserDao;
|
||||
import com.hellogithub.dao.projectDao;
|
||||
import com.hellogithub.entity.projectEntity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import com.hellogithub.dao.categoryDao;
|
||||
import com.hellogithub.dao.projectDao;
|
||||
import com.hellogithub.entity.categoryEntity;
|
||||
import com.hellogithub.entity.projectEntity;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class projectService {
|
||||
|
||||
|
||||
private projectDao projectDao = new projectDao();
|
||||
private categoryDao categoryDao = new categoryDao();
|
||||
/**
|
||||
* 按照期刊号查询
|
||||
*
|
||||
* @param num
|
||||
*/
|
||||
public List<projectEntity> retTerm(String num){
|
||||
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.retTerm(num);
|
||||
for(int i =0;i<projectEntityList.size();i++)
|
||||
{
|
||||
projectEntity projectEntity = projectEntityList.get(i);
|
||||
projectEntity.setCategoryName(dataMap.get(projectEntity.getCategoryId()));
|
||||
categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId());
|
||||
projectEntity.setCategoryName(categoryEntity.getCategoryName());
|
||||
|
||||
}
|
||||
return projectDao.retTerm(num);
|
||||
@@ -59,7 +42,7 @@ public class projectService {
|
||||
*
|
||||
*
|
||||
*/
|
||||
public int countAll() {return projectDao.countAll();}
|
||||
public long countAll() {return projectDao.countAll();}
|
||||
/**
|
||||
* 按照分类检索项目
|
||||
*
|
||||
@@ -69,65 +52,32 @@ public class projectService {
|
||||
return projectDao.retCate(num);
|
||||
}
|
||||
|
||||
public List<projectEntity> retLatestProject(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,"机器学习");
|
||||
public List<projectEntity> retLatestProject(int cate,String name) {
|
||||
List<projectEntity> projectEntityList;
|
||||
if (cate == 0) {
|
||||
projectEntityList =projectDao.retLatestProject();
|
||||
for(int i =0;i<projectEntityList.size();i++)
|
||||
{
|
||||
projectEntity projectEntity = projectEntityList.get(i);
|
||||
projectEntity.setCategoryName(dataMap.get(projectEntity.getCategoryId()));
|
||||
categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId());
|
||||
projectEntity.setCategoryName(categoryEntity.getCategoryName());
|
||||
|
||||
}
|
||||
} else {
|
||||
projectEntityList =projectDao.retSelcetByCate(cate);
|
||||
projectEntityList =projectDao.retSelcetByCate(cate,name);
|
||||
for(int i =0;i<projectEntityList.size();i++)
|
||||
{
|
||||
projectEntity projectEntity = projectEntityList.get(i);
|
||||
projectEntity.setCategoryName(dataMap.get(projectEntity.getCategoryId()));
|
||||
categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId());
|
||||
projectEntity.setCategoryName(categoryEntity.getCategoryName());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return projectEntityList;
|
||||
}
|
||||
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,"机器学习");
|
||||
public List<projectEntity> retSelcetByStar(int cate,String name){
|
||||
|
||||
List<projectEntity> projectEntityList;
|
||||
|
||||
if (cate == 0){
|
||||
@@ -136,47 +86,32 @@ public class projectService {
|
||||
{
|
||||
|
||||
projectEntity projectEntity = projectEntityList.get(i);
|
||||
projectEntity.setCategoryName(dataMap.get(projectEntity.getCategoryId()));
|
||||
categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId());
|
||||
projectEntity.setCategoryName(categoryEntity.getCategoryName());
|
||||
|
||||
}
|
||||
}else {
|
||||
projectEntityList =projectDao.retSelcetByStartNum(cate);
|
||||
projectEntityList =projectDao.retSelcetByStartNum(cate,name);
|
||||
|
||||
for(int i =0;i<projectEntityList.size();i++)
|
||||
{
|
||||
|
||||
projectEntity projectEntity = projectEntityList.get(i);
|
||||
projectEntity.setCategoryName(dataMap.get(projectEntity.getCategoryId()));
|
||||
|
||||
categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId());
|
||||
projectEntity.setCategoryName(categoryEntity.getCategoryName());
|
||||
}
|
||||
}
|
||||
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()));
|
||||
categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId());
|
||||
projectEntity.setCategoryName(categoryEntity.getCategoryName());
|
||||
|
||||
}
|
||||
return projectEntityList;
|
||||
|
@@ -12,6 +12,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
//项目总数接口
|
||||
@WebServlet("/countNum")
|
||||
public class countNumServlet extends HttpServlet {
|
||||
private projectService projectService=new projectService();
|
||||
@@ -39,9 +40,10 @@ public class countNumServlet extends HttpServlet {
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
|
||||
PrintWriter writer = resp.getWriter();
|
||||
String str= "num:"+projectService.countAll();
|
||||
String str= String.valueOf(projectService.countAll());
|
||||
String jsonString = JSONObject.toJSONString(str);
|
||||
writer.println(jsonString);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ public class latestServlet extends HttpServlet {
|
||||
private com.hellogithub.service.projectService projectService=new projectService();
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
|
||||
super.init(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,7 +42,7 @@ public class latestServlet extends HttpServlet {
|
||||
//返回最新期刊数字
|
||||
PrintWriter writer = resp.getWriter();
|
||||
String jsonString = JSONObject.toJSONString(projectService.latestNum());
|
||||
setResultOK("success",writer);
|
||||
// setResultOK("success",writer);
|
||||
writer.println(jsonString);
|
||||
writer.close();
|
||||
}
|
||||
@@ -63,5 +63,10 @@ public class latestServlet extends HttpServlet {
|
||||
public void setResultOK(String msg, PrintWriter writer) {
|
||||
setResult(200, msg, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
62
src/com/hellogithub/servlet/retLabelServlet.java
Normal file
62
src/com/hellogithub/servlet/retLabelServlet.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package com.hellogithub.servlet;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hellogithub.service.categoryService;
|
||||
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;
|
||||
import java.util.HashMap;
|
||||
@WebServlet("/retLabel")
|
||||
public class retLabelServlet extends HttpServlet {
|
||||
private categoryService categoryService=new categoryService();
|
||||
@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 jsonString = JSONObject.toJSONString(categoryService.retLabel());
|
||||
writer.println(jsonString);
|
||||
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);
|
||||
}
|
||||
}
|
@@ -43,8 +43,9 @@ public class selectLastByCateServlet extends HttpServlet {
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
|
||||
String cate = req.getParameter("num");
|
||||
String name = req.getParameter("name");
|
||||
PrintWriter writer = resp.getWriter();
|
||||
String jsonString = JSONObject.toJSONString(projectService.retLatestProject(Integer.valueOf(cate)));
|
||||
String jsonString = JSONObject.toJSONString(projectService.retLatestProject(Integer.valueOf(cate),name));
|
||||
writer.println(jsonString);
|
||||
writer.close();
|
||||
}
|
||||
|
@@ -39,9 +39,9 @@ public class selectMostStarServlet extends HttpServlet {
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
|
||||
String cate = req.getParameter("num");
|
||||
|
||||
String name =req.getParameter("name");
|
||||
PrintWriter writer = resp.getWriter();
|
||||
String jsonString = JSONObject.toJSONString(projectService.retSelcetByStar(Integer.valueOf(cate)));
|
||||
String jsonString = JSONObject.toJSONString(projectService.retSelcetByStar(Integer.valueOf(cate), name));
|
||||
writer.println(jsonString);
|
||||
writer.close();
|
||||
}
|
||||
|
Reference in New Issue
Block a user