java里自定义分页查询的尝试

Posted 德邦总管

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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里自定义分页查询的尝试的主要内容,如果未能解决你的问题,请参考以下文章

在 Java 的 GraphQL 查询中添加片段

java web 分页查询

dedecms更换了ueditor后,在内容模型管理里自定义了几个HTML文本字段无法加载?

Django里自定义用户登陆及登陆后跳转到登陆前页面的实现

Java分页下载

java查询的分页思路!!