关于Jquery easyUI datagrid 分页的问题
Dao的代码
//获取所有的部门信息
public CutPageBean getAllDeptTable(int pageNo,int pageSize){
this.getConnection();
StringBuffer sb = new StringBuffer();
CutPageBean cut = new CutPageBean();
List list = cut.getList();
sb.append("select top ");
sb.append(pageSize);
sb.append(" * from t_dept where id not in(select top ");
sb.append(pageSize*(pageNo-1));
sb.append(" id from t_dept order by id) order by id");
try {
ps = this.con.prepareStatement(sb.toString());
this.rs = this.ps.executeQuery();
while(rs.next()){
DeptBean dept = new DeptBean();
dept.setId(rs.getInt("id"));
dept.setDept_Code(rs.getString("Dept_Code"));
dept.setDept_Name(rs.getString("Dept_Name"));
dept.setMgr_Code(rs.getString("Mgr_Code"));
list.add(dept);
}
ps = this.con.prepareStatement("select count(*) number from t_dept");
rs = ps.executeQuery();
rs.next();
int number = rs.getInt("number");
cut.setTotalPage(number);
} catch (Exception e) {
e.printStackTrace();
}finally{
this.close(rs, ps, con);
}
return cut;
}
----------------------------
CutPageBean代码
public class CutPageBean {
private int totalPage;
private List list = new ArrayList();
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
}
-----------------------------
Action的代码
---------------------------------------------------
public class DeptAction extends ActionSupport{
//每页显示的记录数
private String rows;
//当前第几页
private String page;
//此处定义为JSONObject是因为datagrid默认接收的为json对象而不是json字符串,
//如果定义为string类型的页面读取数据时会报错,我之前报错为rows is not defined
private JSONArray resultObj;
DeptDao d = new DeptDao();
public String getAllDeptTable(){
System.out.println("pageNo:"+page+" pageSize:"+rows);
StringBuffer sb = new StringBuffer();
CutPageBean cut = d.getAllDeptTable(Integer.parseInt(page),Integer.parseInt(rows));