Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1,48 +1,79 @@
|
||||
package com.hellogithub.dao;
|
||||
|
||||
import com.hellogithub.entity.githubEntity;
|
||||
import com.hellogithub.entity.projectEntity;
|
||||
import com.hellogithub.entity.userEntity;
|
||||
import com.hellogithub.utils.JdbcUtils;
|
||||
import com.mysql.cj.jdbc.JdbcConnection;
|
||||
import org.apache.commons.dbutils.QueryRunner;
|
||||
import org.apache.commons.dbutils.handlers.BeanListHandler;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class githubDao {
|
||||
githubEntity githubentity = new githubEntity();
|
||||
|
||||
public int ins_Github_info (int projectId, String name, String starImgUrl, int starCount, String mainLanguage, String isActive, int subscriber, int issues, String isOrganization, String defaultBranch, int forks, String protocol, String version){
|
||||
public int ins_Github_info (int projectId, String avatar,String name, String starImgUrl, int starCount, String mainLanguage, String isActive, int subscriber, int issues, String isOrganization, String defaultBranch, int forks, String protocol, String version){
|
||||
PreparedStatement preparedStatement = null;
|
||||
Connection connection = null;
|
||||
int rs = 0 ;
|
||||
ResultSet rs = null;
|
||||
String sql1 = "SELECT * FROM githubinfo WHERE projectId = ?;";
|
||||
int back = 0 ;
|
||||
try {
|
||||
connection = JdbcUtils.getConnection();
|
||||
String Sql = "INSERT INTO githubinfo(id,projectId,name,starImgUrl,starCount,mainLanguage,isActive,subscriber,issues,isOrganization,defaultBranch,forks,protocol,version,isVaild) VALUES(null,?,?,?,?,?,?,?,?,?,?,?,?,?,0);";
|
||||
preparedStatement = connection.prepareStatement(Sql);
|
||||
preparedStatement.setInt(1, projectId);
|
||||
preparedStatement.setString(2, name);
|
||||
preparedStatement.setString(3, starImgUrl);
|
||||
preparedStatement.setInt(4, starCount);
|
||||
preparedStatement.setString(5, mainLanguage);
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
PreparedStatement prep = conn.prepareStatement(sql1);
|
||||
prep.setInt(1,projectId);
|
||||
rs = prep.executeQuery();
|
||||
if(rs == null){
|
||||
connection = JdbcUtils.getConnection();
|
||||
String Sql = "INSERT INTO githubinfo(id,projectId,avatar,name,starImgUrl,starCount,mainLanguage,isActive,subscriber,issues,isOrganization,defaultBranch,forks,protocol,version,isVaild) VALUES(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0);";
|
||||
preparedStatement = connection.prepareStatement(Sql);
|
||||
preparedStatement.setInt(1, projectId);
|
||||
preparedStatement.setString(2, avatar);
|
||||
preparedStatement.setString(3, name);
|
||||
preparedStatement.setString(4, starImgUrl);
|
||||
preparedStatement.setInt(5, starCount);
|
||||
preparedStatement.setString(6, mainLanguage);
|
||||
|
||||
preparedStatement.setString(6, isActive);
|
||||
preparedStatement.setInt(7, subscriber);
|
||||
preparedStatement.setInt(8, issues);
|
||||
preparedStatement.setString(9, isOrganization);
|
||||
preparedStatement.setString(10, defaultBranch);
|
||||
preparedStatement.setString(7, isActive);
|
||||
preparedStatement.setInt(8, subscriber);
|
||||
preparedStatement.setInt(9, issues);
|
||||
preparedStatement.setString(10, isOrganization);
|
||||
preparedStatement.setString(11, defaultBranch);
|
||||
|
||||
preparedStatement.setInt(11, forks);
|
||||
preparedStatement.setString(12, protocol);
|
||||
preparedStatement.setString(13, version);
|
||||
rs = preparedStatement.executeUpdate();
|
||||
return rs;
|
||||
preparedStatement.setInt(12, forks);
|
||||
preparedStatement.setString(13, protocol);
|
||||
preparedStatement.setString(14, version);
|
||||
back = preparedStatement.executeUpdate();
|
||||
}else{
|
||||
return back;
|
||||
}
|
||||
JdbcUtils.closeConnection(rs,prep,conn);
|
||||
return back;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
} finally {
|
||||
JdbcUtils.closeConnection(preparedStatement, connection);
|
||||
}
|
||||
return rs;
|
||||
return back;
|
||||
}
|
||||
|
||||
public List<githubEntity> ret_Github_info(int projectid){
|
||||
List<githubEntity> githubEntityList;
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql = "select * from githubinfo where projectId = ? and isValid = 1";
|
||||
githubEntityList = runner.query(conn, sql, new BeanListHandler<>(githubEntity.class), projectid);
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return githubEntityList;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -9,6 +9,17 @@ public class githubEntity {
|
||||
private int starCount;
|
||||
private String mainLanguage;
|
||||
private String isActive;
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
private String avatar;
|
||||
|
||||
private int subscriber;
|
||||
private int issues;
|
||||
private String isOrganization;
|
||||
@@ -138,7 +149,7 @@ public class githubEntity {
|
||||
this.isVaild = isVaild;
|
||||
}
|
||||
|
||||
public githubEntity(int id, int projectId, String name, String starImgUrl, int starCount, String mainLanguage, String isActive, int subscriber, int issues, String isOrganization, String defaultBranch, int forks, String protocol, String version, int isVaild) {
|
||||
public githubEntity(int id, int projectId, String name, String starImgUrl, int starCount, String avatar,String mainLanguage, String isActive, int subscriber, int issues, String isOrganization, String defaultBranch, int forks, String protocol, String version, int isVaild) {
|
||||
|
||||
this.id = id;
|
||||
this.projectId = projectId;
|
||||
@@ -155,6 +166,7 @@ public class githubEntity {
|
||||
this.protocol = protocol;
|
||||
this.version = version;
|
||||
this.isVaild = isVaild;
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public githubEntity(){}
|
||||
|
@@ -1,11 +1,27 @@
|
||||
package com.hellogithub.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hellogithub.dao.githubDao;
|
||||
import com.hellogithub.entity.githubEntity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class githubService {
|
||||
private githubDao githubDao = new githubDao();
|
||||
|
||||
public int ins_Github_info(int projectId, String name, String starImgUrl, int starCount, String mainLanguage, String isActive, int subscriber, int issues, String isOrganization, String defaultBranch, int forks, String protocol, String version){
|
||||
return githubDao.ins_Github_info(projectId, name,starImgUrl,starCount, mainLanguage,isActive, subscriber, issues, isOrganization,defaultBranch, forks, protocol, version);
|
||||
public int ins_Github_info(int projectId, String avatar,String name, String starImgUrl, int starCount, String mainLanguage, String isActive, int subscriber, int issues, String isOrganization, String defaultBranch, int forks, String protocol, String version){
|
||||
return githubDao.ins_Github_info(projectId,avatar, name,starImgUrl,starCount, mainLanguage,isActive, subscriber, issues, isOrganization,defaultBranch, forks, protocol, version);
|
||||
}
|
||||
|
||||
public String ret_Github_info(int projectId){
|
||||
List<githubEntity> githubEntityList = githubDao.ret_Github_info(projectId);
|
||||
Map<Integer, githubEntity> dataMap = new HashMap<>();
|
||||
for(int i=1;i<githubEntityList.size()+1;i++){
|
||||
githubEntity githubEntity = githubEntityList.get(i);
|
||||
dataMap.put(i,githubEntity);
|
||||
}
|
||||
return JSONObject.toJSONString(dataMap);
|
||||
}
|
||||
}
|
||||
|
@@ -2,10 +2,10 @@ package com.hellogithub.servlet.githubinfo;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hellogithub.service.githubService;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import java.io.IOException;
|
||||
@@ -35,22 +35,23 @@ public class ins_Github_infoServlet extends HttpServlet {
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
|
||||
PrintWriter writer = resp.getWriter();
|
||||
int projectid = Integer.parseInt(req.getParameter("projectId "));
|
||||
String name = req.getParameter("name ");
|
||||
String starImgUrl = req.getParameter("starImgUrl ");
|
||||
int starCount = Integer.parseInt(req.getParameter("starCount "));
|
||||
String mainLanguage = req.getParameter("mainLanguage ");
|
||||
String isActive = req.getParameter("isActive ");
|
||||
int projectid = Integer.parseInt(req.getParameter("projectId"));
|
||||
String avatar = req.getParameter("avatar");
|
||||
String name = req.getParameter("name");
|
||||
String starImgUrl = req.getParameter("starImgUrl");
|
||||
int starCount = Integer.parseInt(req.getParameter("starCount"));
|
||||
String mainLanguage = req.getParameter("mainLanguage");
|
||||
String isActive = req.getParameter("isActive");
|
||||
|
||||
int subscriber = Integer.parseInt(req.getParameter("subscriber "));
|
||||
int issues = Integer.parseInt(req.getParameter("issues "));
|
||||
String isOrganization = req.getParameter("isOrganization ");
|
||||
String defaultBranch = req.getParameter("defaultBranch ");
|
||||
int forks = Integer.parseInt(req.getParameter("forks "));
|
||||
String protocol = req.getParameter("protocol ");
|
||||
String version = req.getParameter("version ");
|
||||
int subscriber = Integer.parseInt(req.getParameter("subscriber"));
|
||||
int issues = Integer.parseInt(req.getParameter("issues"));
|
||||
String isOrganization = req.getParameter("isOrganization");
|
||||
String defaultBranch = req.getParameter("defaultBranch");
|
||||
int forks = Integer.parseInt(req.getParameter("forks"));
|
||||
String protocol = req.getParameter("protocol");
|
||||
String version = req.getParameter("version");
|
||||
|
||||
int rs = githubservice.ins_Github_info(projectid,name,starImgUrl,starCount, mainLanguage, isActive, subscriber, issues,isOrganization,defaultBranch,forks,protocol,version);
|
||||
int rs = githubservice.ins_Github_info(projectid,avatar,name,starImgUrl,starCount, mainLanguage, isActive, subscriber, issues,isOrganization,defaultBranch,forks,protocol,version);
|
||||
if(rs == 1){
|
||||
setResultOK("插入成功", writer);
|
||||
}else{
|
||||
|
@@ -0,0 +1,42 @@
|
||||
package com.hellogithub.servlet.githubinfo;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hellogithub.service.githubService;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
|
||||
@WebServlet("returnGithubInfo")
|
||||
public class ret_Github_infoServlet extends HttpServlet {
|
||||
private githubService githubservice = new githubService();
|
||||
@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 projectid = req.getParameter("projectId");
|
||||
String jsonString = githubservice.ret_Github_info(Integer.parseInt(projectid));
|
||||
writer.println(jsonString);
|
||||
writer.close();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user