修改随机数,projectDao增加isvalid判断条件
This commit is contained in:
@@ -24,7 +24,7 @@ public class projectDao {
|
|||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
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);
|
projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class), num);
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -42,7 +42,7 @@ public class projectDao {
|
|||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
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));
|
projectEntity = runner.query(conn, sql, new BeanHandler<>(projectEntity.class));
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -61,7 +61,7 @@ public class projectDao {
|
|||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
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));
|
p = runner.query(conn, sql, new BeanHandler<>(projectEntity.class));
|
||||||
count = p.getNum();
|
count = p.getNum();
|
||||||
conn.close();
|
conn.close();
|
||||||
@@ -81,7 +81,7 @@ public class projectDao {
|
|||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
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);
|
projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class), num);
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -94,7 +94,7 @@ public class projectDao {
|
|||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
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));
|
projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class));
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -107,7 +107,7 @@ public class projectDao {
|
|||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
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);
|
projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class),name);
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -121,7 +121,7 @@ public class projectDao {
|
|||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
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);
|
projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class),name);
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -134,7 +134,7 @@ public class projectDao {
|
|||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
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));
|
projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class));
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -148,7 +148,7 @@ public class projectDao {
|
|||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
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);
|
projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class), str);
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -180,7 +180,7 @@ public class projectDao {
|
|||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
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);
|
projectEntity = runner.query(conn, sql, new BeanHandler<>(projectEntity.class),id);
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -197,7 +197,7 @@ public class projectDao {
|
|||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
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);
|
num = runner.update(conn, sql,id);
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -229,7 +229,7 @@ public class projectDao {
|
|||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
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));
|
projectEntity = runner.query(conn, sql,new BeanHandler<>(projectEntity.class));
|
||||||
num = projectEntity.getProjectId();
|
num = projectEntity.getProjectId();
|
||||||
conn.close();
|
conn.close();
|
||||||
|
@@ -158,12 +158,13 @@ public class projectService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<projectEntity> randomSelect(){
|
public List<projectEntity> randomSelect(){
|
||||||
List<projectEntity> projectEntityList = null;
|
List<projectEntity> projectEntityList = new ArrayList<>();
|
||||||
long t = System.currentTimeMillis();
|
long t = System.currentTimeMillis();
|
||||||
Random random = new Random(t);
|
Random random = new Random(t);
|
||||||
|
List<projectEntity> projectEntityList1 = projectDao.retLatestProject();
|
||||||
for(int i=0;i<5;i++)
|
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);
|
projectEntityList.add(projectEntity);
|
||||||
}
|
}
|
||||||
return projectEntityList;
|
return projectEntityList;
|
||||||
|
Reference in New Issue
Block a user