adf 直接在JAVA中使用VO查询相关数据,并分页实现

今天因为要用到ADF 中的BC,也就是直接在JAVA代码中使用VO查询,页面用JSP,不使用ADF标签

经多次验证之下,至少知道VO中分页查询,故有此一记,以备后用

从外部传入JSON串,经解析得到分页中的当前页,和每一页记录数

//这段代码是查询的时候,带参数,并实现分页

public void getJsonDKS618(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
String jsonDKS618 = request.getParameter("jsonDKS618");
PrintWriter printWriter = response.getWriter();
try {
JSONObject ob = new JSONObject(jsonDKS618);
String hsjgdm=ob.getString("HSJGDM");

String dqy=ob.getString("DQY");//当前页
String myjls=ob.getString("MYJLS");//每页记录数
int dqyInt=Integer.valueOf(dqy);
int myjlsInt=Integer.valueOf(myjls);
// HWAppImpl am= new HWAppImpl();
String amDef = "com.mgear.services.HW.App.HWApp";
String amConfig = "HWAppLocal";
ApplicationModule am = Configuration.createRootApplicationModule(amDef, amConfig);
ViewObject vo=am.findViewObject("BW_VO1");
ViewCriteriaManager vcm = vo.getViewCriteriaManager();
ViewCriteria vc = vcm.getViewCriteria("BW_VOCriteria1");
VariableValueManager vvm = vc.ensureVariableManager();
vvm.setVariableValue("hsjgdm", hsjgdm);
vo.setRangeSize(myjlsInt);//设置要获取的记录数,也就是每一页记当数
vo.executeQuery();
int allCount=vo.getRowCount();//经过查询得到总记录数
int zys=(allCount%myjlsInt==0)?(allCount/myjlsInt):(allCount/myjlsInt+1);
vo.scrollRange((dqyInt-1)*myjlsInt);//从哪一条记录开始取数,注意,取得的数目就是上面所设置的
Row[] allRowsInRange = vo.getAllRowsInRange();
String jsonGk="";
for(int i=0;i<allRowsInRange.length;i++){
Row row=allRowsInRange[i];//获取每一条记录内容
// GKBean gb=new GKBean();
// gb.setGkbh(row.getAttribute("Gkbh").toString());
// gb.setGkmc(row.getAttribute("Gkmc").toString());
// gb.setJgdm(row.getAttribute("Hsjgdm").toString());
// gb.setJgmc(row.getAttribute("Zwjc").toString());
jsonGk +="{\"BWBH\":\""+row.getAttribute("Bwbh").toString()+"\",\"HSJGDM\":\""+row.getAttribute("Hsjgdm1").toString()+"\",\"BWMC\":\""+row.getAttribute("Bwmc").toString()+"\",\"HSJG\":\""+row.getAttribute("Zwjc").toString()+"\"},";
}
Configuration.releaseRootApplicationModule(am, true);
if(!jsonGk.equals("")){
jsonGk=jsonGk.substring(0, jsonGk.length()-1);
String json="{\"result\":\"1\",\"info\":\"查询成功!\",\"datas\":{\"tableName\":\"XK_QZTJ\",\"row\":{\"ZJLS\":\""+allCount+"\",\"ZYS\":\""+zys+"\",\"DQY\":\""+dqy+"\",\"MYJLS\":\""+myjls+"\",\"table\":{\"tableName\":\"JC_GK\",\"row\":["+jsonGk+"]}}}}";

printWriter.print(json);//通过输出流写入到页面
printWriter.close();
}else{
String json="{\"result\":\"0\",\"info\":\"查询失败!\"}";
printWriter.print(json);
printWriter.close();
}


} catch (Exception jsone) {
String json="{\"result\":\"0\",\"info\":\"查询失败!\"}";
jsone.printStackTrace();
printWriter.print(json);
printWriter.close();
}
// String resultDKS618 = dataServices.getData("DKS618", jsonDKS618);
// System.out.println(resultDKS618);
// PrintWriter printWriter = response.getWriter();
// printWriter.print(resultDKS618);
}

//下面的代码是查询,不带参数的

public void getJsonDKS622(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
String jsonDKS622 = request.getParameter("jsonWG");
PrintWriter printWriter = response.getWriter();
try {
JSONObject ob = new JSONObject(jsonDKS622);
String dqy=ob.getString("DQY");
String myjls=ob.getString("MYJLS");
int dqyInt=Integer.valueOf(dqy);
int myjlsInt=Integer.valueOf(myjls);
String amDef = "com.mgear.services.HW.App.HWApp";
String amConfig = "HWAppLocal";
ApplicationModule am = Configuration.createRootApplicationModule(amDef, amConfig);
ViewObject vo=am.findViewObject("GyzlWggn_VO1");
vo.setRangeSize(myjlsInt);
vo.executeQuery();
int allCount=vo.getRowCount();
int zys=(allCount%myjlsInt==0)?(allCount/myjlsInt):(allCount/myjlsInt+1);
vo.scrollRange((dqyInt-1)*myjlsInt);
Row[] allRowsInRange = vo.getAllRowsInRange();
String jsonWG="";
for(int i=0;i<allRowsInRange.length;i++){
Row row=allRowsInRange[i];
jsonWG +="{\"UNNO\":\""+((String)row.getAttribute("Unno")==null?"":(String)row.getAttribute("Unno"))+"\",\"ZWMC\":\""+(String)row.getAttribute("Zwmc")+"\",\"WGXH\":\""+(String)row.getAttribute("Wgxh")+"\",\"YWMC\":\""+((String)row.getAttribute("Ywmc")==null?"":(String)row.getAttribute("Ywmc"))+"\",\"WGBH\":\""+(String)row.getAttribute("Wgbh")+"\"},";

}
Configuration.releaseRootApplicationModule(am, true);
if(!jsonWG.equals("")){
jsonWG=jsonWG.substring(0, jsonWG.length()-1);
String json="{\"result\":\"1\",\"info\":\"查询成功!\",\"datas\":{\"tableName\":\"XK_QZTJ\",\"row\":{\"ZJLS\":\""+allCount+"\",\"ZYS\":\""+zys+"\",\"DQY\":\""+dqy+"\",\"MYJLS\":\""+myjls+"\",\"table\":{\"tableName\":\"GYZL_WGGN\",\"row\":["+jsonWG+"]}}}}";

printWriter.print(json);
printWriter.close();
}else{
String json="{\"result\":\"0\",\"info\":\"查询失败!\"}";
printWriter.print(json);
printWriter.close();
}


} catch (Exception jsone) {
String json="{\"result\":\"0\",\"info\":\"查询失败!\"}";
jsone.printStackTrace();
printWriter.print(json);
printWriter.close();
}

你可能感兴趣的:(java)