修改随机推荐

This commit is contained in:
cyk
2023-07-04 10:59:54 +08:00
parent ab979671e8
commit 3c1f800884
2 changed files with 11 additions and 20 deletions

View File

@@ -156,22 +156,6 @@ public class projectDao {
} }
return projectEntityList; return projectEntityList;
} }
// //返回标签
// public List<> retAllLabelBy(String str) {
// List<projectEntity> projectEntityList;
// try {
// Connection conn = JdbcUtils.getConnection();
// QueryRunner runner = new QueryRunner();
// String sql = "SELECT * FROM project WHERE projectName LIKE %?%";
// projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class), str);
// conn.close();
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// return ;
// }
/** /**
* 根据项目ID返回项目所有内容 * 根据项目ID返回项目所有内容
*/ */

View File

@@ -18,8 +18,6 @@ public class projectService {
private categoryDao categoryDao = new categoryDao(); private categoryDao categoryDao = new categoryDao();
/** /**
* 按照期刊号查询 * 按照期刊号查询
*
* @param num
*/ */
public String retTerm(String num){ public String retTerm(String num){
List<projectEntity> projectEntityList = projectDao.retTerm(num); List<projectEntity> projectEntityList = projectDao.retTerm(num);
@@ -162,13 +160,22 @@ 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();
for(int i=0;i<5;i++) 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())
{ {
projectEntity projectEntity =projectEntityList1.get(random.nextInt(projectEntityList1.size())); int id = it.next();
projectEntity projectEntity =projectEntityList1.get(id);
categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId()); categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId());
projectEntity.setCategoryName(categoryEntity.getCategoryName()); projectEntity.setCategoryName(categoryEntity.getCategoryName());
projectEntityList.add(projectEntity); projectEntityList.add(projectEntity);
System.out.println(id);
} }
return projectEntityList; return projectEntityList;
} }
} }