easyUI datagrid 分頁參數page和rows


Struts2獲取easyUI datagrid 分頁參數page和rows

 

用pageHelper分頁時,只要是能夠獲取前台傳來的兩個參數page和rows基本就完成了很大一部分。

獲取方法:定義兩個變量page和rows,設置對應的getter,setter方法,在方法中直接獲取就能打得。easyUI默認的每次請求時都會傳遞這兩個參數。

[java] view plain copy 在CODE上查看代碼片派生到我的代碼片
  1. public int getPage() {  
  2.         return page;  
  3.     }  
  4.   
  5.     public void setPage(int page) {  
  6.         this.page = page;  
  7.     }  
  8.   
  9.     public int getRows() {  
  10.         return rows;  
  11.     }  
  12.   
  13.     public void setRows(int rows) {  
  14.         this.rows = rows;  
  15.     }  


[java] view plain copy 在CODE上查看代碼片派生到我的代碼片
  1. public String getAllPages() {     
  2.         List<Emp> plist = empDao.findAll();  
  3.         PageHelper.startPage(page, rows);  
  4.         List<Emp> elist = empDao.findAll();  
  5.         // 判斷  
  6.         if (elist.size() > 0) {  
  7.             map.put("total", plist.size());  
  8.             map.put("rows", elist);  
  9.             return SUCCESS;  
  10.         }  
  11.         return ERROR;  
  12.     }  
  13.       


返回的數據必須轉成json格式

[html] view plain copy 在CODE上查看代碼片派生到我的代碼片
    1. <!-- 配置查詢所有方法Action -->  
    2.         <action name="listAction" class="EmpAction" method="getAllPages">  
    3.             <result name="success" type="json">  
    4.                 <param name="root">map</param>  
    5.             </result>  
    6.         </action

 

springmvc

 

page,rows分頁請求參數,rows和total結果參數

@RequestMapping(value = "/getSalaryList.rst", method = {RequestMethod.GET, RequestMethod.POST})
@ResponseBody
public Object getSalaryList (int page,int rows,@RequestParam(value="key",required=false) String key){
ICoreRequestContext ctx = CoreRequestContextUtil.getCoreRequestContext();
SSOUser ssoUser = ctx.getCurrentUser();
if (ssoUser.isAnonymous()) {
//return new Result(ResultCode.ERROR.getCode(),"用戶未登錄");
return alertError("用戶未登錄!");
}
HiberSession dbSession = null;
/* LostPropPermissionChecker.checkPermission(this.getAccessContext());*/
try {
dbSession = (HiberSession) CoreplusEnv.getDBSessionFactory().getDBSession();
dbSession.beginTransaction();
Map<String, Object> params = new HashMap<String, Object>();//參數集合
if(!StringUtil.isEmpty(key)){
params.put("key", "%"+key+"%");
}
params.put("begin", page-1);
params.put("length", rows);
LightAppDBUtil _dbUtil = LightAppDBUtil.getInstance();
Query query = _dbUtil.parserNamedQuery(dbSession, "getSalaryList", params);
//轉譯成需要的類Salary
ResultTransformer rt = Transformers.aliasToBean(Salary.class);
List<Salary> salaryList = query.setResultTransformer(rt).list();
JSONObject result= new JSONObject();
if (salaryList == null || salaryList.isEmpty()) {
result.put("total", 0);
result.put("rows", salaryList);
return result;
}
int total=inquiryTotal();
// jo.put("errMsg", "");
result.put("rows", salaryList);
result.put("total", total);
// return new DataGridVO(total,salaryList);
return result;
} catch (Exception e) {
_log.error("查詢工資列表失敗!", e);
dbSession.rollback();
return alertError("查詢工資列表異常");
} finally {
closeSession(dbSession);
}

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM