Hibernate+Struts分頁代碼(節選)
轉自:http://blog.csdn.net/yeno/archive/2007/01/25/1492788.aspx
public?class?HibernateUtil?{
????private?HibernateUtil(){}??
????/**
?????*?執行數據庫查詢,返回結果集List
?????*?@param?hsql?HSQL查詢語句
?????*?@return?list?結果集
?????*/
????public?static?List?query(String?hql)?{
????????List?list?=?null;
????????Query?query?=?null;?????
????????Session?sess?=?HibernateSessionFactory.currentSession();
????????try{
????????????//創建一條HQL查詢語句
????????????if?(hql.toLowerCase().contains("from?"))
????????????????query?=?sess.createQuery(hql);
????????????else
?????????????????query?=?sess.getNamedQuery(hql);
???????????
????????????list?=?query.list();
???????????
????????}catch(HibernateException?e)??{
????????????System.out.println("Hibernate?Exception:@"+e.getMessage());
????????????throw?new?RuntimeException(e);
????????}finally?{
????????????HibernateSessionFactory.closeSession();
????????}
????????return?list;
????}
????public?static?List?query(String?hql,?Object?bean){
????????List?list?=?null;
????????Query?query?=?null;
???????
????????Session?sess?=?HibernateSessionFactory.currentSession();
????????try?{
????????????//創建一條HQL查詢語句
????????????if?(hql.toLowerCase().contains("from?"))
????????????????query?=?sess.createQuery(hql);
????????????else
?????????????????query?=?sess.getNamedQuery(hql);
???????????
????????????query.setProperties(bean);
????????????list?=?query.list();
????????}catch(HibernateException?e)?{
????????????System.out.println("Hibernate?Exception:@"+e.getMessage());
????????????throw?new?RuntimeException(e);
????????}?finally?{
????????????HibernateSessionFactory.closeSession();
????????}
????????return?list;
????}
}
這里是分頁段的實現代碼,分別繼承AbstractSearch和AbstractList,實現預查詢和分頁查詢:SearchCompany(預查詢)、BaseComSearch(分頁查詢),代碼如下:
package?com.nyhr.struts.search;
import?com.nyhr.struts.frame.AbstractSearch;
import?com.nyhr.struts.form.SearchCompanyForm;
import?org.apache.struts.action.ActionForm;
public?class?SearchCompany?extends?AbstractSearch{
????private?StringBuffer?sql;
????private?SearchCompanyForm?form;
????private?TempWhere?bean;
????/**直接由默認查詢語句構造?*/
????public?SearchCompany(){???????
????????sql?=?new?StringBuffer("select?companyId?from?SysCompany");
????}
????/**
?????*?由指定查詢語句查詢
?????*?@param?hql
?????*/
????public?SearchCompany(String?hql){
????????sql?=?new?StringBuffer(hql);
????}
????/**
?????*?由formBean構造查詢語句及參數實體
?????*?@param?form
?????*/
????public?SearchCompany(ActionForm?form){
????????sql?=?new?StringBuffer("");
????????sql.append("select?c.companyId?from?Company?as?c?left?join?fetch?c.companyProps?as?p?left?join?fetch?c.contactInfo?as?ct?");
????????this.form?=?(SearchCompanyForm)form;
????????condition();
????}
????/**調用父類的帶參查詢返回結果*/
????public?Object[]?getList(){
????????if(sql==null)????return?null;
????????if(bean==null)
????????????return?getIDList(sql.toString());
????????else
????????????return?getIDList(sql.toString(),?bean);
????}
????/**
?????*?條件查詢(條件語句及參數實體在此設定)
?????*/
????protected?void?condition(){
????????bean?=?new?TempWhere();
????????sql.append("?WHERE?p.lockedFlag=0?");
????????if(!form.getCompanyName().equals("")){
????????????sql.append("?AND?c.companyName=:companyName");
????????????bean.setCompanyName(form.getCompanyName());
????????}???????????
????????if?(!form.getLinkTel().equals("")){
????????????sql.append("?AND?ct.linkTel=:linkTel");
????????????bean.setLinkTel(form.getLinkTel());
????????}
????????if?(!form.getLinkFax().equals("")){
????????????sql.append("?AND?ct.linkFax=:linkFax");
????????????bean.setLinkFax(form.getLinkFax());
????????}
????????if?(!form.getLinkEmail().equals("")){
????????????sql.append("?AND?ct.linkEmail=:linkEmail");
????????????bean.setLinkEmail(form.getLinkEmail());
????????}
????????if?(!form.getLinkman().equals("")){
????????????sql.append("?AND?ct.linkman=:linkman");
????????????bean.setLinkman(form.getLinkman());
????????}
????????if?(!form.getRepute().equals("")){
????????????sql.append("?AND?p.repute=:repute");
????????????bean.setRepute(Short.parseShort(form.getRepute()));
????????}
????????if?(!form.getSpecification().equals("")){
????????????sql.append("?AND?p.specification=:specification");
????????????bean.setSpecification(Short.parseShort(form.getSpecification()));
????????}
????????if?(!form.getVipFlag().equals("")){
????????????sql.append("?AND?p.vipflag=:vipFlag");
????????????bean.setVipFlag(Short.parseShort(form.getVipFlag()));
????????}
????????if?(!form.getDistrict().equals("")){
????????????sql.append("?AND?p.district=:district");
????????????bean.setDistrict(Short.parseShort(form.getDistrict()));
????????}
????????if?(!form.getFealty().equals("")){
????????????sql.append("?AND?p.fealty=:fealty");
????????????bean.setFealty(Short.parseShort(form.getFealty()));
????????}
????????if?(!form.getSourceFlag().equals("")){
????????????sql.append("?AND?p.sourceFlag=:sourceFlag");
????????????bean.setSourceFlag(Short.parseShort(form.getSourceFlag()));
????????}
????????if?(!form.getCompanyProps().equals("")){
????????????sql.append("?AND?c.companyProps_1=:companyProps");
????????????bean.setCompanyProps(Short.parseShort(form.getCompanyProps()));
????????}
????????if?(!form.getCalling().equals("")){
????????????sql.append("?AND?p.calling=:calling");
????????????bean.setCalling(Short.parseShort(form.getCalling()));
????????}
????}
???
????class?TempWhere{
????????/**?companyProps?property?*/
????????private?short?companyProps;
????????/**?linkman?property?*/
????????private?String?linkman;
????????/**?fealty?property?*/
????????private?short?fealty;
????????/**?comapnyName?property?*/
????????private?String?companyName;
????????/**?district?property?*/
????????private?short?district;
????????/**?lockedFlag?property?*/
????????private?byte?lockedFlag;
????????/**?linkFax?property?*/
????????private?String?linkFax;
????????/**?specification?property?*/
????????private?short?specification;
????????/**?linkEmail?property?*/
????????private?String?linkEmail;
????????/**?sourceFlag?property?*/
????????private?short?sourceFlag;
????????/**?linkTel?property?*/
????????private?String?linkTel;
????????/**?repute?property?*/
????????private?short?repute;
????????/**?calling?property?*/
????????private?short?calling;
????????/**?vipFlag?property?*/
????????private?short?vipFlag;
????????public?TempWhere()?{
????????????super();
????????????//?TODO?自動生成構造函數存根
????????}
????????public?TempWhere(short?companyProps,?String?linkman,?short?fealty,?String?companyName,?short?district,?byte?lockedFlag,?String?linkFax,?short?specification,?String?linkEmail,?short?sourceFlag,?String?linkTel,?short?repute,?short?calling,?short?vipFlag)?{
????????????super();
????????????//?TODO?自動生成構造函數存根
????????????this.companyProps?=?companyProps;
????????????this.linkman?=?linkman;
????????????this.fealty?=?fealty;
????????????this.companyName?=?companyName;
????????????this.district?=?district;
????????????this.lockedFlag?=?lockedFlag;
????????????this.linkFax?=?linkFax;
????????????this.specification?=?specification;
????????????this.linkEmail?=?linkEmail;
????????????this.sourceFlag?=?sourceFlag;
????????????this.linkTel?=?linkTel;
????????????this.repute?=?repute;
????????????this.calling?=?calling;
????????????this.vipFlag?=?vipFlag;
????????}
????????public?short?getCalling()?{
????????????return?calling;
????????}
????????public?void?setCalling(short?calling)?{
????????????this.calling?=?calling;
????????}
????????public?String?getCompanyName()?{
????????????return?companyName;
????????}
????????public?void?setCompanyName(String?companyName)?{
????????????this.companyName?=?companyName;
????????}
????????public?short?getCompanyProps()?{
????????????return?companyProps;
????????}
????????public?void?setCompanyProps(short?companyProps)?{
????????????this.companyProps?=?companyProps;
????????}
????????public?short?getDistrict()?{
????????????return?district;
????????}
????????public?void?setDistrict(short?district)?{
????????????this.district?=?district;
????????}
????????public?short?getFealty()?{
????????????return?fealty;
????????}
????????public?void?setFealty(short?fealty)?{
????????????this.fealty?=?fealty;
????????}
????????public?String?getLinkEmail()?{
????????????return?linkEmail;
????????}
????????public?void?setLinkEmail(String?linkEmail)?{
????????????this.linkEmail?=?linkEmail;
????????}
????????public?String?getLinkFax()?{
????????????return?linkFax;
????????}
????????public?void?setLinkFax(String?linkFax)?{
????????????this.linkFax?=?linkFax;
????????}
????????public?String?getLinkman()?{
????????????return?linkman;
????????}
????????public?void?setLinkman(String?linkman)?{
????????????this.linkman?=?linkman;
????????}
????????public?String?getLinkTel()?{
????????????return?linkTel;
????????}
????????public?void?setLinkTel(String?linkTel)?{
????????????this.linkTel?=?linkTel;
????????}
????????public?byte?getLockedFlag()?{
????????????return?lockedFlag;
????????}
????????public?void?setLockedFlag(byte?lockedFlag)?{
????????????this.lockedFlag?=?lockedFlag;
????????}
????????public?short?getRepute()?{
????????????return?repute;
????????}
????????public?void?setRepute(short?repute)?{
????????????this.repute?=?repute;
????????}
????????public?short?getSourceFlag()?{
????????????return?sourceFlag;
????????}
????????public?void?setSourceFlag(short?sourceFlag)?{
????????????this.sourceFlag?=?sourceFlag;
????????}
????????public?short?getSpecification()?{
????????????return?specification;
????????}
????????public?void?setSpecification(short?specification)?{
????????????this.specification?=?specification;
????????}
????????public?short?getVipFlag()?{
????????????return?vipFlag;
????????}
????????public?void?setVipFlag(short?vipFlag)?{
????????????this.vipFlag?=?vipFlag;
????????}
????}
}
package?com.nyhr.struts.search;
import?com.nyhr.struts.frame.AbstractList;
import?com.nyhr.struts.page.Page;
import?org.apache.struts.action.ActionForm;
public?class?BaseComSearch?extends?AbstractList?{
????/**預查詢分頁,由默認HQL構造初始化查詢*/
????public?BaseComSearch(){
????????super(new?SearchCompany());???????
????}
????/**預查詢分頁,由指定HQL構造初始化查詢*/
????public?BaseComSearch(String?hql){
????????super(new?SearchCompany(hql));???????
????}
????/**
?????*?預查詢分頁,由ActionForm構造初始化查詢
?????*?@param?form?formBean
?????*/
????public?BaseComSearch(ActionForm?form){
????????super(new?SearchCompany(form));
????}
????/**
?????*?查詢分頁(分頁查詢)
?????*?@param?idList
?????*?@param?page
?????*/
????public?BaseComSearch(Object[]?idList,Page?page){
????????super(page,?idList);
????}
????@Override
????public?String?getHql(){
????????return?"from?SysCompany?sc?where?sc.companyId?in?(:idList)";
????}???
}
BaseComSearch類是對外的入口,Action調用的代碼如下(加粗部分就是調用的指令):
public?class?HibernateUtil?{
????private?HibernateUtil(){}??
????/**
?????*?執行數據庫查詢,返回結果集List
?????*?@param?hsql?HSQL查詢語句
?????*?@return?list?結果集
?????*/
????public?static?List?query(String?hql)?{
????????List?list?=?null;
????????Query?query?=?null;?????
????????Session?sess?=?HibernateSessionFactory.currentSession();
????????try{
????????????//創建一條HQL查詢語句
????????????if?(hql.toLowerCase().contains("from?"))
????????????????query?=?sess.createQuery(hql);
????????????else
?????????????????query?=?sess.getNamedQuery(hql);
???????????
????????????list?=?query.list();
???????????
????????}catch(HibernateException?e)??{
????????????System.out.println("Hibernate?Exception:@"+e.getMessage());
????????????throw?new?RuntimeException(e);
????????}finally?{
????????????HibernateSessionFactory.closeSession();
????????}
????????return?list;
????}
????public?static?List?query(String?hql,?Object?bean){
????????List?list?=?null;
????????Query?query?=?null;
???????
????????Session?sess?=?HibernateSessionFactory.currentSession();
????????try?{
????????????//創建一條HQL查詢語句
????????????if?(hql.toLowerCase().contains("from?"))
????????????????query?=?sess.createQuery(hql);
????????????else
?????????????????query?=?sess.getNamedQuery(hql);
???????????
????????????query.setProperties(bean);
????????????list?=?query.list();
????????}catch(HibernateException?e)?{
????????????System.out.println("Hibernate?Exception:@"+e.getMessage());
????????????throw?new?RuntimeException(e);
????????}?finally?{
????????????HibernateSessionFactory.closeSession();
????????}
????????return?list;
????}
}
這里是分頁段的實現代碼,分別繼承AbstractSearch和AbstractList,實現預查詢和分頁查詢:SearchCompany(預查詢)、BaseComSearch(分頁查詢),代碼如下:
package?com.nyhr.struts.search;
import?com.nyhr.struts.frame.AbstractSearch;
import?com.nyhr.struts.form.SearchCompanyForm;
import?org.apache.struts.action.ActionForm;
public?class?SearchCompany?extends?AbstractSearch{
????private?StringBuffer?sql;
????private?SearchCompanyForm?form;
????private?TempWhere?bean;
????/**直接由默認查詢語句構造?*/
????public?SearchCompany(){???????
????????sql?=?new?StringBuffer("select?companyId?from?SysCompany");
????}
????/**
?????*?由指定查詢語句查詢
?????*?@param?hql
?????*/
????public?SearchCompany(String?hql){
????????sql?=?new?StringBuffer(hql);
????}
????/**
?????*?由formBean構造查詢語句及參數實體
?????*?@param?form
?????*/
????public?SearchCompany(ActionForm?form){
????????sql?=?new?StringBuffer("");
????????sql.append("select?c.companyId?from?Company?as?c?left?join?fetch?c.companyProps?as?p?left?join?fetch?c.contactInfo?as?ct?");
????????this.form?=?(SearchCompanyForm)form;
????????condition();
????}
????/**調用父類的帶參查詢返回結果*/
????public?Object[]?getList(){
????????if(sql==null)????return?null;
????????if(bean==null)
????????????return?getIDList(sql.toString());
????????else
????????????return?getIDList(sql.toString(),?bean);
????}
????/**
?????*?條件查詢(條件語句及參數實體在此設定)
?????*/
????protected?void?condition(){
????????bean?=?new?TempWhere();
????????sql.append("?WHERE?p.lockedFlag=0?");
????????if(!form.getCompanyName().equals("")){
????????????sql.append("?AND?c.companyName=:companyName");
????????????bean.setCompanyName(form.getCompanyName());
????????}???????????
????????if?(!form.getLinkTel().equals("")){
????????????sql.append("?AND?ct.linkTel=:linkTel");
????????????bean.setLinkTel(form.getLinkTel());
????????}
????????if?(!form.getLinkFax().equals("")){
????????????sql.append("?AND?ct.linkFax=:linkFax");
????????????bean.setLinkFax(form.getLinkFax());
????????}
????????if?(!form.getLinkEmail().equals("")){
????????????sql.append("?AND?ct.linkEmail=:linkEmail");
????????????bean.setLinkEmail(form.getLinkEmail());
????????}
????????if?(!form.getLinkman().equals("")){
????????????sql.append("?AND?ct.linkman=:linkman");
????????????bean.setLinkman(form.getLinkman());
????????}
????????if?(!form.getRepute().equals("")){
????????????sql.append("?AND?p.repute=:repute");
????????????bean.setRepute(Short.parseShort(form.getRepute()));
????????}
????????if?(!form.getSpecification().equals("")){
????????????sql.append("?AND?p.specification=:specification");
????????????bean.setSpecification(Short.parseShort(form.getSpecification()));
????????}
????????if?(!form.getVipFlag().equals("")){
????????????sql.append("?AND?p.vipflag=:vipFlag");
????????????bean.setVipFlag(Short.parseShort(form.getVipFlag()));
????????}
????????if?(!form.getDistrict().equals("")){
????????????sql.append("?AND?p.district=:district");
????????????bean.setDistrict(Short.parseShort(form.getDistrict()));
????????}
????????if?(!form.getFealty().equals("")){
????????????sql.append("?AND?p.fealty=:fealty");
????????????bean.setFealty(Short.parseShort(form.getFealty()));
????????}
????????if?(!form.getSourceFlag().equals("")){
????????????sql.append("?AND?p.sourceFlag=:sourceFlag");
????????????bean.setSourceFlag(Short.parseShort(form.getSourceFlag()));
????????}
????????if?(!form.getCompanyProps().equals("")){
????????????sql.append("?AND?c.companyProps_1=:companyProps");
????????????bean.setCompanyProps(Short.parseShort(form.getCompanyProps()));
????????}
????????if?(!form.getCalling().equals("")){
????????????sql.append("?AND?p.calling=:calling");
????????????bean.setCalling(Short.parseShort(form.getCalling()));
????????}
????}
???
????class?TempWhere{
????????/**?companyProps?property?*/
????????private?short?companyProps;
????????/**?linkman?property?*/
????????private?String?linkman;
????????/**?fealty?property?*/
????????private?short?fealty;
????????/**?comapnyName?property?*/
????????private?String?companyName;
????????/**?district?property?*/
????????private?short?district;
????????/**?lockedFlag?property?*/
????????private?byte?lockedFlag;
????????/**?linkFax?property?*/
????????private?String?linkFax;
????????/**?specification?property?*/
????????private?short?specification;
????????/**?linkEmail?property?*/
????????private?String?linkEmail;
????????/**?sourceFlag?property?*/
????????private?short?sourceFlag;
????????/**?linkTel?property?*/
????????private?String?linkTel;
????????/**?repute?property?*/
????????private?short?repute;
????????/**?calling?property?*/
????????private?short?calling;
????????/**?vipFlag?property?*/
????????private?short?vipFlag;
????????public?TempWhere()?{
????????????super();
????????????//?TODO?自動生成構造函數存根
????????}
????????public?TempWhere(short?companyProps,?String?linkman,?short?fealty,?String?companyName,?short?district,?byte?lockedFlag,?String?linkFax,?short?specification,?String?linkEmail,?short?sourceFlag,?String?linkTel,?short?repute,?short?calling,?short?vipFlag)?{
????????????super();
????????????//?TODO?自動生成構造函數存根
????????????this.companyProps?=?companyProps;
????????????this.linkman?=?linkman;
????????????this.fealty?=?fealty;
????????????this.companyName?=?companyName;
????????????this.district?=?district;
????????????this.lockedFlag?=?lockedFlag;
????????????this.linkFax?=?linkFax;
????????????this.specification?=?specification;
????????????this.linkEmail?=?linkEmail;
????????????this.sourceFlag?=?sourceFlag;
????????????this.linkTel?=?linkTel;
????????????this.repute?=?repute;
????????????this.calling?=?calling;
????????????this.vipFlag?=?vipFlag;
????????}
????????public?short?getCalling()?{
????????????return?calling;
????????}
????????public?void?setCalling(short?calling)?{
????????????this.calling?=?calling;
????????}
????????public?String?getCompanyName()?{
????????????return?companyName;
????????}
????????public?void?setCompanyName(String?companyName)?{
????????????this.companyName?=?companyName;
????????}
????????public?short?getCompanyProps()?{
????????????return?companyProps;
????????}
????????public?void?setCompanyProps(short?companyProps)?{
????????????this.companyProps?=?companyProps;
????????}
????????public?short?getDistrict()?{
????????????return?district;
????????}
????????public?void?setDistrict(short?district)?{
????????????this.district?=?district;
????????}
????????public?short?getFealty()?{
????????????return?fealty;
????????}
????????public?void?setFealty(short?fealty)?{
????????????this.fealty?=?fealty;
????????}
????????public?String?getLinkEmail()?{
????????????return?linkEmail;
????????}
????????public?void?setLinkEmail(String?linkEmail)?{
????????????this.linkEmail?=?linkEmail;
????????}
????????public?String?getLinkFax()?{
????????????return?linkFax;
????????}
????????public?void?setLinkFax(String?linkFax)?{
????????????this.linkFax?=?linkFax;
????????}
????????public?String?getLinkman()?{
????????????return?linkman;
????????}
????????public?void?setLinkman(String?linkman)?{
????????????this.linkman?=?linkman;
????????}
????????public?String?getLinkTel()?{
????????????return?linkTel;
????????}
????????public?void?setLinkTel(String?linkTel)?{
????????????this.linkTel?=?linkTel;
????????}
????????public?byte?getLockedFlag()?{
????????????return?lockedFlag;
????????}
????????public?void?setLockedFlag(byte?lockedFlag)?{
????????????this.lockedFlag?=?lockedFlag;
????????}
????????public?short?getRepute()?{
????????????return?repute;
????????}
????????public?void?setRepute(short?repute)?{
????????????this.repute?=?repute;
????????}
????????public?short?getSourceFlag()?{
????????????return?sourceFlag;
????????}
????????public?void?setSourceFlag(short?sourceFlag)?{
????????????this.sourceFlag?=?sourceFlag;
????????}
????????public?short?getSpecification()?{
????????????return?specification;
????????}
????????public?void?setSpecification(short?specification)?{
????????????this.specification?=?specification;
????????}
????????public?short?getVipFlag()?{
????????????return?vipFlag;
????????}
????????public?void?setVipFlag(short?vipFlag)?{
????????????this.vipFlag?=?vipFlag;
????????}
????}
}
package?com.nyhr.struts.search;
import?com.nyhr.struts.frame.AbstractList;
import?com.nyhr.struts.page.Page;
import?org.apache.struts.action.ActionForm;
public?class?BaseComSearch?extends?AbstractList?{
????/**預查詢分頁,由默認HQL構造初始化查詢*/
????public?BaseComSearch(){
????????super(new?SearchCompany());???????
????}
????/**預查詢分頁,由指定HQL構造初始化查詢*/
????public?BaseComSearch(String?hql){
????????super(new?SearchCompany(hql));???????
????}
????/**
?????*?預查詢分頁,由ActionForm構造初始化查詢
?????*?@param?form?formBean
?????*/
????public?BaseComSearch(ActionForm?form){
????????super(new?SearchCompany(form));
????}
????/**
?????*?查詢分頁(分頁查詢)
?????*?@param?idList
?????*?@param?page
?????*/
????public?BaseComSearch(Object[]?idList,Page?page){
????????super(page,?idList);
????}
????@Override
????public?String?getHql(){
????????return?"from?SysCompany?sc?where?sc.companyId?in?(:idList)";
????}???
}
BaseComSearch類是對外的入口,Action調用的代碼如下(加粗部分就是調用的指令):
/*****************************預查詢分頁調用
????public?ActionForward?execute(
????????ActionMapping?mapping,
????????ActionForm?form,
????????HttpServletRequest?request,
????????HttpServletResponse?response)?{
????????SearchCompanyForm?searchCompanyForm?=?(SearchCompanyForm)?form;
????????//?TODO?Auto-generated?method?stub
????????BaseComSearch?com?=?new?BaseComSearch(searchCompanyForm);
????????Result?result?=?com.getResult();
????????String?idList?=?com.getIdList();
????????List?list?=?result.getContent();
????????Page?page?=?result.getPage();
????????request.setAttribute("idList",idList);
????????request.setAttribute("list",list);
????????request.setAttribute("page",page);
????????request.setAttribute("search",searchCompanyForm);
????????//return?null;
????????return?mapping.findForward("search");
????}
/*****************************查詢分頁調用
????public?ActionForward?execute(
????????ActionMapping?mapping,
????????ActionForm?form,
????????HttpServletRequest?request,
????????HttpServletResponse?response)?{
????????//?TODO?Auto-generated?method?stub
????????int?totalRecords?=?Integer.parseInt(request.getParameter("totalRecords"));
????????int?everyPage?=?Integer.parseInt(request.getParameter("everyPage"));
????????int?currentPage?=?Integer.parseInt(request.getParameter("currentPage"));
????????Page?page?=?PageUtil.createPage(everyPage,currentPage,totalRecords);
????????System.out.println("totalRecords:"+totalRecords+"?everyPage:"+everyPage+"?currentPage:"+currentPage);
???????
????????Result?result;
????????String?forward;
????????String?idList?=?request.getParameter("idList");
????????if(idList?==null?||?idList.equals("")){
????????????result?=?new?BaseComSearch().getResult();
????????????request.setAttribute("idList","");
????????????forward="page";
????????}else{
????????????Object[]?idLists?=?StringUtil.stringToArray(idList,"[^\\d]+|,");
????????????System.out.println(idLists[2]);
????????????result?=?new?BaseComSearch(idLists,page).getResult();
????????????request.setAttribute("idList",idList);
????????????forward="pages";
????????}
????????List?list?=?result.getContent();
???????
????????request.setAttribute("page",page);
????????request.setAttribute("list",list);
????????return?mapping.findForward(forward);
????}
????public?ActionForward?execute(
????????ActionMapping?mapping,
????????ActionForm?form,
????????HttpServletRequest?request,
????????HttpServletResponse?response)?{
????????SearchCompanyForm?searchCompanyForm?=?(SearchCompanyForm)?form;
????????//?TODO?Auto-generated?method?stub
????????BaseComSearch?com?=?new?BaseComSearch(searchCompanyForm);
????????Result?result?=?com.getResult();
????????String?idList?=?com.getIdList();
????????List?list?=?result.getContent();
????????Page?page?=?result.getPage();
????????request.setAttribute("idList",idList);
????????request.setAttribute("list",list);
????????request.setAttribute("page",page);
????????request.setAttribute("search",searchCompanyForm);
????????//return?null;
????????return?mapping.findForward("search");
????}
/*****************************查詢分頁調用
????public?ActionForward?execute(
????????ActionMapping?mapping,
????????ActionForm?form,
????????HttpServletRequest?request,
????????HttpServletResponse?response)?{
????????//?TODO?Auto-generated?method?stub
????????int?totalRecords?=?Integer.parseInt(request.getParameter("totalRecords"));
????????int?everyPage?=?Integer.parseInt(request.getParameter("everyPage"));
????????int?currentPage?=?Integer.parseInt(request.getParameter("currentPage"));
????????Page?page?=?PageUtil.createPage(everyPage,currentPage,totalRecords);
????????System.out.println("totalRecords:"+totalRecords+"?everyPage:"+everyPage+"?currentPage:"+currentPage);
???????
????????Result?result;
????????String?forward;
????????String?idList?=?request.getParameter("idList");
????????if(idList?==null?||?idList.equals("")){
????????????result?=?new?BaseComSearch().getResult();
????????????request.setAttribute("idList","");
????????????forward="page";
????????}else{
????????????Object[]?idLists?=?StringUtil.stringToArray(idList,"[^\\d]+|,");
????????????System.out.println(idLists[2]);
????????????result?=?new?BaseComSearch(idLists,page).getResult();
????????????request.setAttribute("idList",idList);
????????????forward="pages";
????????}
????????List?list?=?result.getContent();
???????
????????request.setAttribute("page",page);
????????request.setAttribute("list",list);
????????return?mapping.findForward(forward);
????}
posted on 2007-08-07 00:47 藍色幽默 閱讀(356) 評論(0) 編輯 收藏 所屬分類: Hibernate