随即选择文章例子

if ("selectblog".equals(actiontype)) {
        List<Blogs> list = new ArrayList<Blogs>();
        Integer start = blogdao.getMinIdBlogs(subdomainid);
        Integer end = blogdao.getMaxIdBlogs(subdomainid);
        Set<Integer> usedids = (Set<Integer>) request.getSession(true).getAttribute("randomblogids");
        if (usedids == null
                  || usedids.size() >= end / BlogsListAction.RANDOM_NUMBER
                  || usedids.size() >= end - start) {
                   usedids = new HashSet<Integer>();
          }
        if (end - start <= BlogsListAction.RANDOM_NUMBER) {
                for (int id = start; id <= end; id++) {
              Blogs blogs = blogdao.getBlogsByblogidAndSubdmid(id,subdomainid);
         if (blogs != null) {
              list.add(blogs);
         }
       }
        request.setAttribute("randomblogids", null);
   } else {
    while (list.size() <= BlogsListAction.RANDOM_NUMBER) {
     Integer id = RandomSelectDataUtil.next(start, end);
     if (usedids.contains(id)) {
      continue;
     } else {
      usedids.add(id);
      Blogs blogs = blogdao.getBlogsByblogidAndSubdmid(id,
        subdomainid);
      if (blogs != null) {
       list.add(blogs);
      }
     }
     if (usedids.size() >= end - start)
      break;
    }
   }
   List<Blogs> blogsslist = new ArrayList<Blogs>();
   for (Blogs b : list) {
    List<BlogsCommonts> blogcomm = blogdao
      .findBlogsCommontsByBlogsid(b.getBlogsid());
    b.setExtFields1(String.valueOf(blogcomm.size()));
    blogsslist.add(b);
   }
   List<Blogs> bloglist = new ArrayList<Blogs>();
   for (Blogs blogs : blogsslist) {
    Blogs temp = new Blogs();
    PropertyUtilsExt.copyProperties(temp, blogs);
    String content = DocumentUtil.gethtmltext(blogs.getContent());
    content = content.replaceAll("&nbsp;", "");
    content = content.replaceAll("&hellip;", "……");
    temp.setContent(content);
    bloglist.add(temp);
   }
   request.setAttribute("listblogs", bloglist);
   request.getSession(true).setAttribute("randomblogids", usedids);
   return mapping.findForward("listselect");
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值