优化
This commit is contained in:
@@ -45,6 +45,7 @@ public class AdminDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="UPDATE admin SET loginTime = ? WHERE adminName= ? and isValid = 1";
|
String sql="UPDATE admin SET loginTime = ? WHERE adminName= ? and isValid = 1";
|
||||||
num = runner.update(conn,sql,loginTime,name);
|
num = runner.update(conn,sql,loginTime,name);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -127,6 +128,7 @@ public class AdminDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="select * from admin";
|
String sql="select * from admin";
|
||||||
adminEntityList = runner.query(conn,sql,new BeanListHandler<>(adminEntity.class));
|
adminEntityList = runner.query(conn,sql,new BeanListHandler<>(adminEntity.class));
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -141,6 +143,7 @@ public class AdminDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="update admin set adminName = ? , adminPassword = ?, loginTime = ? ,isValid =? where adminId =? ";
|
String sql="update admin set adminName = ? , adminPassword = ?, loginTime = ? ,isValid =? where adminId =? ";
|
||||||
num = runner.update(conn,sql,adminName, adminPassword,loginTime, isValid,adminId);
|
num = runner.update(conn,sql,adminName, adminPassword,loginTime, isValid,adminId);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -155,6 +158,7 @@ public class AdminDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="delete from admin where adminId = ?";
|
String sql="delete from admin where adminId = ?";
|
||||||
num = runner.update(conn,sql,id);
|
num = runner.update(conn,sql,id);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -169,6 +173,7 @@ public class AdminDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="UPDATE user SET isValid = ? WHERE userId = ?";
|
String sql="UPDATE user SET isValid = ? WHERE userId = ?";
|
||||||
num = runner.update(conn, sql, isvalid,id);
|
num = runner.update(conn, sql, isvalid,id);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -182,6 +187,7 @@ public class AdminDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="UPDATE project SET isValid = ? WHERE userId = ?";
|
String sql="UPDATE project SET isValid = ? WHERE userId = ?";
|
||||||
num = runner.update(conn, sql, isvalid,id);
|
num = runner.update(conn, sql, isvalid,id);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -196,6 +202,7 @@ public class AdminDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="UPDATE comment SET isValid = ? WHERE userId = ?";
|
String sql="UPDATE comment SET isValid = ? WHERE userId = ?";
|
||||||
num = runner.update(conn, sql, isvalid,id);
|
num = runner.update(conn, sql, isvalid,id);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -210,6 +217,7 @@ public class AdminDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="UPDATE category SET isValid = ? WHERE userId = ?";
|
String sql="UPDATE category SET isValid = ? WHERE userId = ?";
|
||||||
num = runner.update(conn, sql, isvalid,id);
|
num = runner.update(conn, sql, isvalid,id);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -224,6 +232,7 @@ public class AdminDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="UPDATE article SET isValid = ? WHERE userId = ?";
|
String sql="UPDATE article SET isValid = ? WHERE userId = ?";
|
||||||
num = runner.update(conn, sql, isvalid,id);
|
num = runner.update(conn, sql, isvalid,id);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -238,6 +247,7 @@ public class AdminDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="UPDATE admin SET isValid = ? WHERE userId = ?";
|
String sql="UPDATE admin SET isValid = ? WHERE userId = ?";
|
||||||
num = runner.update(conn, sql, isvalid,id);
|
num = runner.update(conn, sql, isvalid,id);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@@ -222,6 +222,7 @@ public class articleDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="select * from article";
|
String sql="select * from article";
|
||||||
articleEntityList = runner.query(conn,sql,new BeanListHandler<>(articleEntity.class));
|
articleEntityList = runner.query(conn,sql,new BeanListHandler<>(articleEntity.class));
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -236,6 +237,7 @@ public class articleDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="update article set userId = ? , articleContent = ? , publishTime = ? ,isValid =?, readCount=?, articleTitle=?, articleIco=? where articleId =? ";
|
String sql="update article set userId = ? , articleContent = ? , publishTime = ? ,isValid =?, readCount=?, articleTitle=?, articleIco=? where articleId =? ";
|
||||||
num = runner.update(conn,sql,userId, articleContent , publishTime , isValid, readCount, articleTitle, articleIco ,articleId);
|
num = runner.update(conn,sql,userId, articleContent , publishTime , isValid, readCount, articleTitle, articleIco ,articleId);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -250,6 +252,7 @@ public class articleDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="delete from article where articleId = ?";
|
String sql="delete from article where articleId = ?";
|
||||||
num = runner.update(conn,sql,id);
|
num = runner.update(conn,sql,id);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@@ -56,6 +56,7 @@ public class categoryDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="select * from category ";
|
String sql="select * from category ";
|
||||||
categoryEntityList = runner.query(conn,sql,new BeanListHandler<>(categoryEntity.class));
|
categoryEntityList = runner.query(conn,sql,new BeanListHandler<>(categoryEntity.class));
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -70,6 +71,7 @@ public class categoryDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="update category set category = ? , categoryName = ? ,isValid =? where categoryId =? ";
|
String sql="update category set category = ? , categoryName = ? ,isValid =? where categoryId =? ";
|
||||||
num = runner.update(conn,sql,category, categoryName, isValid,categoryId);
|
num = runner.update(conn,sql,category, categoryName, isValid,categoryId);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -84,6 +86,7 @@ public class categoryDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="delete from category where articleId = ?";
|
String sql="delete from category where articleId = ?";
|
||||||
num = runner.update(conn,sql,id);
|
num = runner.update(conn,sql,id);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@@ -116,6 +116,7 @@ public class commentDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="select * from comment ";
|
String sql="select * from comment ";
|
||||||
commentEntityList = runner.query(conn,sql,new BeanListHandler<>(commentEntity.class));
|
commentEntityList = runner.query(conn,sql,new BeanListHandler<>(commentEntity.class));
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -130,6 +131,7 @@ public class commentDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="update comment set userId = ? , projectId = ? , content = ? ,isUsed =?, commentTime=?, isValid=?,star=?,likeNum=?where commentId =? ";
|
String sql="update comment set userId = ? , projectId = ? , content = ? ,isUsed =?, commentTime=?, isValid=?,star=?,likeNum=?where commentId =? ";
|
||||||
num = runner.update(conn,sql,userId, projectId , content , isUsed, commentTime, isValid, star, likeNum ,commentId);
|
num = runner.update(conn,sql,userId, projectId , content , isUsed, commentTime, isValid, star, likeNum ,commentId);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -144,6 +146,7 @@ public class commentDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="delete from comment where commentId = ?";
|
String sql="delete from comment where commentId = ?";
|
||||||
num = runner.update(conn,sql,id);
|
num = runner.update(conn,sql,id);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@@ -67,6 +67,7 @@ public class githubDao {
|
|||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
githubEntityList = runner.query(conn,sql,new BeanHandler<>(githubEntity.class),projectid);
|
githubEntityList = runner.query(conn,sql,new BeanHandler<>(githubEntity.class),projectid);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@@ -324,6 +324,7 @@ public class projectDao {
|
|||||||
return 1;
|
return 1;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -343,6 +344,7 @@ public class projectDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="select * from project ";
|
String sql="select * from project ";
|
||||||
projectEntityList = runner.query(conn,sql,new BeanListHandler<>(projectEntity.class));
|
projectEntityList = runner.query(conn,sql,new BeanListHandler<>(projectEntity.class));
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -357,6 +359,7 @@ public class projectDao {
|
|||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="update project set userId = ? , projectName = ? , projectUrl = ? ,projectIco =?, projectTitle=?, projectDescription=?,startNum=?,submitTime=?,categoryId=?,isValid=? ,fileAddress = ? , periodicals = ? ,lookCount = ? where projectId =? ";
|
String sql="update project set userId = ? , projectName = ? , projectUrl = ? ,projectIco =?, projectTitle=?, projectDescription=?,startNum=?,submitTime=?,categoryId=?,isValid=? ,fileAddress = ? , periodicals = ? ,lookCount = ? where projectId =? ";
|
||||||
num = runner.update(conn,sql,userId, projectName , projectUrl , projectIco, projectTitle, projectDescription, startNum, submitTime ,categoryId,isValid,fileAddress,periodicals,lookCount,projectId);
|
num = runner.update(conn,sql,userId, projectName , projectUrl , projectIco, projectTitle, projectDescription, startNum, submitTime ,categoryId,isValid,fileAddress,periodicals,lookCount,projectId);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -375,6 +378,7 @@ public class projectDao {
|
|||||||
runner.update(conn,sql,id);
|
runner.update(conn,sql,id);
|
||||||
sql="delete from project_category where projectId = ?";
|
sql="delete from project_category where projectId = ?";
|
||||||
runner.update(conn,sql,id);
|
runner.update(conn,sql,id);
|
||||||
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@@ -195,21 +195,34 @@ public class projectService {
|
|||||||
long t = System.currentTimeMillis();
|
long t = System.currentTimeMillis();
|
||||||
Random random = new Random(t);
|
Random random = new Random(t);
|
||||||
List<projectEntity> projectEntityList1 = projectDao.retLatestProject();
|
List<projectEntity> projectEntityList1 = projectDao.retLatestProject();
|
||||||
Set<Integer> integers =new HashSet<>();
|
if(projectEntityList1.size()<5)
|
||||||
while(integers.size()<5){
|
|
||||||
int num = random.nextInt(projectEntityList1.size());
|
|
||||||
integers.add(num);
|
|
||||||
}
|
|
||||||
Iterator<Integer> it = integers.iterator();
|
|
||||||
while(it.hasNext())
|
|
||||||
{
|
{
|
||||||
int id = it.next();
|
for(int i=0;i<projectEntityList1.size();i++)
|
||||||
projectEntity projectEntity =projectEntityList1.get(id);
|
{
|
||||||
categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId());
|
projectEntity projectEntity =projectEntityList1.get(i);
|
||||||
projectEntity.setCategoryName(categoryEntity.getCategoryName());
|
categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId());
|
||||||
projectEntityList.add(projectEntity);
|
projectEntityList1.get(i).setCategoryName(categoryEntity.getCategoryName());
|
||||||
|
}
|
||||||
|
projectEntityList = projectEntityList1;
|
||||||
|
}else{
|
||||||
|
Set<Integer> integers =new HashSet<>();
|
||||||
|
while(integers.size()<5){
|
||||||
|
int num = random.nextInt(projectEntityList1.size());
|
||||||
|
integers.add(num);
|
||||||
|
}
|
||||||
|
Iterator<Integer> it = integers.iterator();
|
||||||
|
while(it.hasNext())
|
||||||
|
{
|
||||||
|
int id = it.next();
|
||||||
|
projectEntity projectEntity =projectEntityList1.get(id);
|
||||||
|
categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId());
|
||||||
|
projectEntity.setCategoryName(categoryEntity.getCategoryName());
|
||||||
|
projectEntityList.add(projectEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return projectEntityList;
|
return projectEntityList;
|
||||||
}
|
}
|
||||||
public String retProjectByUserId(int id){
|
public String retProjectByUserId(int id){
|
||||||
|
Reference in New Issue
Block a user