发布项目时查询
This commit is contained in:
@@ -6,12 +6,10 @@ 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.BeanHandler;
|
||||
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.sql.*;
|
||||
import java.util.List;
|
||||
|
||||
public class githubDao {
|
||||
@@ -62,18 +60,24 @@ public class githubDao {
|
||||
return back;
|
||||
}
|
||||
|
||||
public List<githubEntity> ret_Github_info(int projectid){
|
||||
public ResultSetMetaData ret_Github_info(int projectid) {
|
||||
List<githubEntity> githubEntityList;
|
||||
ResultSetMetaData rsmd = null;
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
PreparedStatement prep = null;
|
||||
ResultSet rs = null;
|
||||
String sql = "select * from githubinfo where projectId = ? and isValid = 1";
|
||||
githubEntityList = runner.query(conn, sql, new BeanListHandler<>(githubEntity.class), projectid);
|
||||
prep = conn.prepareStatement(sql);
|
||||
prep.setInt(1, projectid);
|
||||
while (rs.next()) {
|
||||
rsmd = rs.getMetaData();
|
||||
}
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return githubEntityList;
|
||||
return rsmd;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.hellogithub.dao.githubDao;
|
||||
import com.hellogithub.entity.githubEntity;
|
||||
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -16,12 +17,7 @@ public class githubService {
|
||||
}
|
||||
|
||||
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);
|
||||
ResultSetMetaData rsmd = githubDao.ret_Github_info(projectId);
|
||||
return JSONObject.toJSONString(rsmd);
|
||||
}
|
||||
}
|
||||
|
@@ -35,8 +35,7 @@ public class ret_Github_infoServlet extends HttpServlet {
|
||||
|
||||
PrintWriter writer = resp.getWriter();
|
||||
String projectid = req.getParameter("projectId");
|
||||
String jsonString = githubservice.ret_Github_info(Integer.parseInt(projectid));
|
||||
writer.println(jsonString);
|
||||
writer.println(githubservice.ret_Github_info(Integer.parseInt(projectid)););
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user