diff --git a/src/com/hellogithub/dao/projectDao.java b/src/com/hellogithub/dao/projectDao.java index 4a74a59..376e097 100644 --- a/src/com/hellogithub/dao/projectDao.java +++ b/src/com/hellogithub/dao/projectDao.java @@ -24,7 +24,7 @@ public class projectDao { try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql = "select * from project where periodicals = ? ORDER BY categoryId"; + String sql = "select * from project where periodicals = ? and isValid = 1ORDER BY categoryId"; projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class), num); conn.close(); } catch (SQLException e) { @@ -42,7 +42,7 @@ public class projectDao { try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql = "select * from project Order BY periodicals DESC limit 1"; + String sql = "select * from project where isValid = 1 Order BY periodicals DESC limit 1"; projectEntity = runner.query(conn, sql, new BeanHandler<>(projectEntity.class)); conn.close(); } catch (SQLException e) { @@ -61,7 +61,7 @@ public class projectDao { try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql = "select count(*) as num from project"; + String sql = "select count(*) as num from project where isValid = 1"; p = runner.query(conn, sql, new BeanHandler<>(projectEntity.class)); count = p.getNum(); conn.close(); @@ -81,7 +81,7 @@ public class projectDao { try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql = "select * from project where categoryId = ?"; + String sql = "select * from project where categoryId = ? and isValid = 1"; projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class), num); conn.close(); } catch (SQLException e) { @@ -94,7 +94,7 @@ public class projectDao { try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql = "select * from project;"; + String sql = "select * from project where isValid = 1 "; projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class)); conn.close(); } catch (SQLException e) { @@ -107,7 +107,7 @@ public class projectDao { try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql = "select * from project where projectId in (select projectId from project_category where categoryId in(select categoryId from category where categoryName = ?))"; + String sql = "select * from project where isValid = 1 and 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) { @@ -121,7 +121,7 @@ public class projectDao { try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - 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"; + String sql = "select * from project where isValid = 1 and 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) { @@ -134,7 +134,7 @@ public class projectDao { try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql = "select * from project order by lookCount desc"; + String sql = "select * from project where isValid = 1 order by lookCount desc"; projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class)); conn.close(); } catch (SQLException e) { @@ -148,7 +148,7 @@ public class projectDao { try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql = "SELECT * FROM project WHERE projectName LIKE %?%"; + String sql = "SELECT * FROM project WHERE isValid = 1 and projectName LIKE %?%"; projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class), str); conn.close(); } catch (SQLException e) { @@ -180,7 +180,7 @@ public class projectDao { try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql = "select * from project where projectId = ?"; + String sql = "select * from project where isValid = 1 and projectId = ?"; projectEntity = runner.query(conn, sql, new BeanHandler<>(projectEntity.class),id); conn.close(); } catch (SQLException e) { @@ -197,7 +197,7 @@ public class projectDao { try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql = "UPDATE project SET lookcount = lookcount+1 WHERE projectId= ?"; + String sql = "UPDATE project SET lookcount = lookcount+1 WHERE isValid = 1 and projectId= ? "; num = runner.update(conn, sql,id); conn.close(); } catch (SQLException e) { @@ -229,7 +229,7 @@ public class projectDao { try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql = "select * from project Order By ProjectId DESC limit 1"; + String sql = "select * from project where isValid = 1 Order By ProjectId DESC limit 1"; projectEntity = runner.query(conn, sql,new BeanHandler<>(projectEntity.class)); num = projectEntity.getProjectId(); conn.close(); diff --git a/src/com/hellogithub/service/projectService.java b/src/com/hellogithub/service/projectService.java index 60cb444..b5e204e 100644 --- a/src/com/hellogithub/service/projectService.java +++ b/src/com/hellogithub/service/projectService.java @@ -158,12 +158,13 @@ public class projectService { } public List randomSelect(){ - List projectEntityList = null; + List projectEntityList = new ArrayList<>(); long t = System.currentTimeMillis(); Random random = new Random(t); + List projectEntityList1 = projectDao.retLatestProject(); for(int i=0;i<5;i++) { - projectEntity projectEntity = projectDao.selectProById(String.valueOf(random.nextInt(projectDao.retMaxProId()))); + projectEntity projectEntity =projectEntityList1.get(random.nextInt(projectEntityList1.size())); projectEntityList.add(projectEntity); } return projectEntityList;