-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoticeLimitAction.java
More file actions
135 lines (101 loc) · 2.99 KB
/
NoticeLimitAction.java
File metadata and controls
135 lines (101 loc) · 2.99 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.nxdcms.action;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.record.formula.functions.T;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.junit.Test;
import com.nxdcms.dao.impl.PageBean;
import com.nxdcms.entity.Notice;
import com.nxdcms.entity.PageObject;
import com.nxdcms.entity.Subcompetition;
import com.opensymphony.xwork2.Action;
import utils.HibernateUtils;
import utils.LimitDao;
public class NoticeLimitAction implements Action {
//获取表单的值
private String pageSize ;
private String curPage ;
private String ntitle ;
private String ndate ;
private PageObject result = null;
@Override
public String execute() throws Exception {
//调试使用
System.out.println("当前页"+curPage+"每页行数"+pageSize+ntitle+ndate);
//定义查询条件
Criterion criterion0=null,criterion1=null,criterion2=null;
//创建hibernate的session
Session session = HibernateUtils.getSession();
//定义hibernate所要查询类
Class ObjClass = null;
try {
//实例化要查询的类名
ObjClass = Class.forName("com.nxdcms.entity.Notice");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//过滤查询条件,没有查询条件就将空值传入方法
if(ntitle!=null&&!"".equals(ntitle)&&!"null".equals(ntitle)){
criterion0 = Restrictions.like("noticeContent", ntitle);
}else{
System.out.println("ntitle null");
}
if(ndate!=null&&!"".equals(ndate)&&!"null".equals(ndate)){
criterion1 = Restrictions.like("noticeDate",ndate);
}else{
System.out.println("ndate null");
}
//定义排序(降序/升序)
Order order = Order.asc("noticeDate");
//参数传入工具,返回一个具体的分页类
//注意最后三个查询条件可以不止三个,理论可以传入无限多个查询条件
result = LimitDao.queryByPage(session, Integer.parseInt(pageSize), Integer.parseInt(curPage), ObjClass, order,
criterion0, criterion1);
//调试使用
if (result == null) {
System.out.println("po null");
} else {
System.out.println("OOK");
for (Object o : result.getList()) {
Notice s = (Notice) o;
System.out.println(s.getNoticeContent());
}
}
System.out.println(result);
return "success";
}
public String getPageSize() {
return pageSize;
}
public void setPageSize(String pageSize) {
this.pageSize = pageSize;
}
public String getCurPage() {
return curPage;
}
public void setCurPage(String curPage) {
this.curPage = curPage;
}
public String getNtitle() {
return ntitle;
}
public void setNtitle(String ntitle) {
this.ntitle = ntitle;
}
public String getNdate() {
return ndate;
}
public void setNdate(String ndate) {
this.ndate = ndate;
}
public PageObject getResult() {
return result;
}
public void setResult(PageObject result) {
this.result = result;
}
}