首页 > 代码库 > java里自定义分页查询的尝试
java里自定义分页查询的尝试
1 public String list(){ 2 try { 3 LoginUser loginUser = getLoginUser();//获取当前登录用户 4 if(curpage<=0){ 5 curpage=1; 6 } 7 pagesize=15; 8 RunParam runParam = runParamService.getTzrqrq(); 9 10 if(faccountDate == null){ 11 faccountDate = runParam.getfItemDouDate(); 12 if(faccountDate == null){ 13 faccountDate = MyUtils.nowYmDate(); 14 } 15 } 16 17 String s1=faccountDate.substring(0, 4); 18 String s2=faccountDate.substring(5, 7); 19 s1+=s2; 20 21 String sql = "SELECT FContainerNO,FHappenCompanyNO,FHappenCompanyName,FContainerTypeNO,FContainerTypeName,"; 22 sql += "FContainerName,FAccountDate,SUM(FQuantity_K) AS FQuantity_K,SUM(FQuantity_QC) AS FQuantity_QC,SUM(FQuantity_RK) AS FQuantity_RK,SUM(FQuantity_CK) AS FQuantity_CK,"; 23 sql += "SUM(FQuantity_BS) AS FQuantity_BS,SUM(FQuantity_FX) AS FQuantity_FX,SUM(FQuantity_PC) AS FQuantity_PC FROM V_Bus_StoConAIAOAcc"; 24 sql += " WHERE FAccountDate=‘"+s1+"‘"; 25 if(fhappenCompanyNO!=null&&!"".equals(fhappenCompanyNO)){ 26 sql+=" and FHappenCompanyNO=‘"+fhappenCompanyNO+"‘or FHappenCompanyName=‘"+fhappenCompanyNO+"‘"; 27 } 28 if("2".equals(loginUser.getUserType())){ 29 sql+=" and FHappenCompanyNO=‘"+loginUser.getSupplierCode()+"‘"; 30 } 31 if(fcontainerNO!=null&&!"".equals(fcontainerNO)){ 32 sql+=" and FContainerNO=‘"+fcontainerNO+"‘ or FContainerName=‘"+fcontainerNO+"‘"; 33 } 34 sql += " GROUP BY FContainerTypeNO,FContainerTypeName,FHappenCompanyNO,FHappenCompanyName,FContainerNO,FContainerName,FAccountDate "; 35 sql += " ORDER BY FHappenCompanyNO,FContainerTypeNO,FContainerNO "; 36 // sql = " SELECT TOP "+15 +" og.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY FHappenCompanyNO,FContainerTypeNO,FContainerNO) AS rownumber,o.* FROM ("+sql+") AS o) AS og WHERE og.rownumber>"+pagesize*(curpage-1); 37 stoConAIAOAccList = dbHelper.query(sql); 38 List<StoConAIAOAcc> list=new ArrayList<StoConAIAOAcc>(); 39 int i=1; 40 for(Map map:stoConAIAOAccList){ 41 if(i>pagesize*(curpage-1)&&i<=pagesize*curpage){ 42 StoConAIAOAcc stoConAIAOAcc=new StoConAIAOAcc(); 43 stoConAIAOAcc.setFcontainerNO(map.get("FContainerNO")==null?"":map.get("FContainerNO").toString()); 44 stoConAIAOAcc.setFcontainerName(map.get("FContainerName")==null?"":map.get("FContainerName").toString()); 45 stoConAIAOAcc.setFhappenComNO(map.get("FHappenCompanyNO")==null?"":map.get("FHappenCompanyNO").toString()); 46 stoConAIAOAcc.setFhappenComName(map.get("FHappenCompanyName")==null?"":map.get("FHappenCompanyName").toString()); 47 stoConAIAOAcc.setFcontainerTypeNO(map.get("FContainerTypeNO")==null?"":map.get("FContainerTypeNO").toString()); 48 stoConAIAOAcc.setFcontainerTypeName(map.get("FContainerTypeName")==null?"":map.get("FContainerTypeName").toString()); 49 stoConAIAOAcc.setFaccountDate(map.get("FAccountDate")==null?"":map.get("FAccountDate").toString()); 50 stoConAIAOAcc.setFquantityk(map.get("FQuantity_K")==null?"":map.get("FQuantity_K").toString()); 51 stoConAIAOAcc.setFquantityQC(map.get("FQuantity_QC")==null?"":map.get("FQuantity_QC").toString()); 52 stoConAIAOAcc.setFquantityRK(map.get("FQuantity_RK")==null?"":map.get("FQuantity_RK").toString()); 53 stoConAIAOAcc.setFquantityCK(map.get("FQuantity_CK")==null?"":map.get("FQuantity_CK").toString()); 54 stoConAIAOAcc.setFquantityBS(map.get("FQuantity_BS")==null?"":map.get("FQuantity_BS").toString()); 55 stoConAIAOAcc.setFquantityFX(map.get("FQuantity_FX")==null?"":map.get("FQuantity_FX").toString()); 56 stoConAIAOAcc.setFquantityPC(map.get("FQuantity_PC")==null?"":map.get("FQuantity_PC").toString()); 57 list.add(stoConAIAOAcc); 58 } 59 i++; 60 } 61 PageModel<StoConAIAOAcc> stoConAIAOAccPage1=new PageModel<StoConAIAOAcc>(); 62 stoConAIAOAccPage1.setReList(list); 63 stoConAIAOAccPage1.setCurPage(curpage); 64 stoConAIAOAccPage1.setPerindex(curpage>1?(curpage-1):-1); 65 stoConAIAOAccPage1.setNextindex(curpage<(stoConAIAOAccList.size()%pagesize>0?(stoConAIAOAccList.size()/pagesize+1):(stoConAIAOAccList.size()/pagesize))?(curpage+1):-1); 66 stoConAIAOAccPage1.setItemCount(stoConAIAOAccList.size()); 67 stoConAIAOAccPage1.setTotalPage(stoConAIAOAccList.size()%pagesize>0?(stoConAIAOAccList.size()/pagesize+1):(stoConAIAOAccList.size()/pagesize)); 68 stoConAIAOAccPage1.setPageSize(pagesize); 69 stoConAIAOAccPage=stoConAIAOAccPage1; 70 71 supplierList = supplierService.getAllIsp(); 72 73 } catch (Exception e) { 74 e.printStackTrace(); 75 } 76 return "stoConAIAOAccList"; 77 }
java里自定义分页查询的尝试
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。