forked from maxliaops/Java_Web_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlogMainAction.java
More file actions
69 lines (61 loc) · 2.32 KB
/
BlogMainAction.java
File metadata and controls
69 lines (61 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.mr.webiter;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.mr.dao.ObjectDao;
import com.mr.model.ArticleInfo;
import com.mr.model.UserInfo;
import com.opensymphony.xwork2.ActionSupport;
/**
* 执行首页操作的类
* @author CHUNBIN
*
*/
public class BlogMainAction extends ActionSupport implements
ServletRequestAware {
protected HttpServletRequest request;
private ObjectDao<UserInfo> userDao = new ObjectDao<UserInfo>();
private ObjectDao<ArticleInfo> articleDao = new ObjectDao<ArticleInfo>();
private String hql_user_commend = null;
private String hql_user_vistor = null;
private String hql_article_commend = null;
private String hql_article_vistor = null;
public BlogMainAction() {
hql_user_commend = "from UserInfo where commend='是' and freeze='解冻'";
hql_user_vistor = "from UserInfo where freeze='解冻' order by vistor desc";
hql_article_commend = "from ArticleInfo where commend='是' and author in (select account from UserInfo where freeze='解冻')";
hql_article_vistor = "from ArticleInfo where author in (select account from UserInfo where freeze='解冻') order by visit desc";
}
public String BlogMain() {
// 以下上判断博客推荐
List<UserInfo> userCommned = userDao.queryList(hql_user_commend);
if (userCommned.size() > 5) {
userCommned = userCommned.subList(0, 5);
}
request.setAttribute("userCommned", userCommned);
// 以下是热门博客
List<UserInfo> userVistor = userDao.queryList(hql_user_vistor);
if (userVistor.size() > 5) {
userVistor = userVistor.subList(0, 5);
}
request.setAttribute("userVistor", userVistor);
// 以下是推荐文章
List<ArticleInfo> articleCommend = articleDao
.queryListObject(hql_article_commend);
if (articleCommend.size() > 5) {
articleCommend = articleCommend.subList(0, 5);
}
request.setAttribute("articleCommend", articleCommend);
// 以下是热门文章
List<ArticleInfo> articleVistor = articleDao
.queryListObject(hql_article_vistor);
if (articleVistor.size() > 5) {
articleVistor = articleVistor.subList(0, 5);
}
request.setAttribute("articleVistor", articleVistor);
return "blogMain";
}
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
}