/** Blog分页 */ @Override @Transactional @SuppressWarnings({"rawtypes", "unchecked"}) public PageConf findBlogPageList( int start, int limit, UserInfo userInfo, String type, Integer blogId) throws BlogException { try { String sql = " select temp_0.rowno from (select @rowno := @rowno + 1 as rowno , module.id as id from Blog as module " + " , (select @rowno := 0 ) as t_rowno "; // 通用查询匹配 if (type != null) { // 找到blogId所在位置 Long indexStart = 0L; if (type.equals("friend") && userInfo != null) { sql += " and exists ( select friend.friend.id from Friend friend " + " where friend.friend.id = module.userInfo.id and friend.userId = ? ) " + " order by module.createTime desc "; System.out.println(sql); List<Object[]> countList = baseDao.findSql(sql, blogId); if (countList.iterator().hasNext()) { Object[] obj = countList.iterator().next(); indexStart = (Long) obj[0]; } System.out.println(indexStart); } else if (type.equals("my") && userInfo != null) { // 查询我自己的日志 sql += " where module.userId = ? order by module.createTime desc ) as temp_0 where temp_0.id = ? "; System.out.println(sql); List<Object[]> countList = baseDao.findSql(sql, userInfo.getId(), blogId); if (countList.iterator().hasNext()) { Object[] obj = countList.iterator().next(); indexStart = ((Double) obj[0]).longValue(); } System.out.println(indexStart); } else if (type.equals("all")) { // sql += " order by module.createTime desc ) as temp_0 where temp_0.id = ? "; System.out.println(sql); List<Object[]> countList = baseDao.findSql(sql, blogId); if (countList.iterator().hasNext()) { Object[] obj = countList.iterator().next(); indexStart = ((Double) obj[0]).longValue(); } System.out.println(indexStart); } // 再次进行分页查询 // 分页是从0开始所以-1 // 处理第一篇文章 return findBlogPageList(indexStart.intValue() - 1, limit, userInfo, type); } else { return null; } } catch (Exception e) { throw new BlogException("Blog分页异常"); } }