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(" ", "");
content = content.replaceAll("…", "……");
temp.setContent(content);
bloglist.add(temp);
}
request.setAttribute("listblogs", bloglist);
request.getSession(true).setAttribute("randomblogids", usedids);
return mapping.findForward("listselect");
}
随即选择文章例子
最新推荐文章于 2010-01-08 15:21:00 发布