struts加hibernate中分页显示问题的解决
hibernate 的查询语句"from TbFitment where 1=1 and ......"
此查询语句查询出来的结果List中的记录。在显示页面,struts的<logic:iterate>
标签可以把结果List的中的object[]自动识别为TbFitment类 javaBean。
可以使用<td
在显示页面,struts 会自动构造 TbFitmentSearch javaBean 循环显示。
struts ation 类 代码:
package com.sunco.fitment.request.action;
import java.util.List;
import javax.servlet.http.*;
import java.util.List;
import com.sunco.base.action.BaseAction;
import com.sunco.fitment.hibernate.TbFitment;
import com.sunco.fitment.hibernate.dao.*;
import com.sunco.fitment.request.form.*;
import org.apache.struts.action.*;
import com.sunco.base.common.*;
import com.sunco.base.common.HttpServletBean;
import com.sunco.base.common.UserFace;
import net.sf.hibernate.Query;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
import java.util.Vector;
import java.util.Iterator;
import java.util.*;
public class RequestSearchListAction
extends BaseAction {
// /**
// * 此处不允许覆写该类 public ActionForward execute()
// * @param actionMapping ActionMapping
// * @param actionForm ActionForm
// * @param resp HttpServletRequest
// * @param req HttpServletResponse
// * @return ActionForward
// */
// public ActionForward execute(ActionMapping actionMapping,
// ActionForm actionForm, HttpServletRequest resp,
// HttpServletResponse req) {
// }
/**
*
* @param actionMapping ActionMapping
* @param actionForm ActionForm
* @param req HttpServletRequest
* @param resp HttpServletResponse
* @throws Exception
* @return ActionForward
*/
public ActionForward exec(ActionMapping actionMapping, ActionForm actionForm
, HttpServletRequest req,
HttpServletResponse resp, HttpServletBean hsBean)
throws Exception {
RequestSearchForm requestSearchForm = (RequestSearchForm) actionForm;
String fitid = requestSearchForm.getFitid();
String FK_REGIONNAMEALL = "&"+requestSearchForm.getDistrict1()
+"&"+requestSearchForm.getDistrict2()
+"&"+requestSearchForm.getDistrict3();
String address = requestSearchForm.getAddress();
String begindate = requestSearchForm.getBegindate();
String enddate = requestSearchForm.getEnddate();
String reqstatus = requestSearchForm.getReqstatus();
String gname = requestSearchForm.getGname();
String gtelephone = requestSearchForm.getGtelephone();
String clientsource = requestSearchForm.getClientsource();
String vdept = requestSearchForm.getVdept();
if (clientsource.equals("请选择"))
clientsource = "";
if (reqstatus.equals("全部"))
reqstatus = "";
file://查询语句 查询条件大原则:※不包括撤单和成交的 ※下次回访日期未过期的 ---------未设置过滤
String HQLStr = "from TbFitmentSearch as tf";
// String HQLStr = "select tf.ifAssign ,tf.reqCode ,tf.status,tf.manageDeptName ,"
// +"tf.inputDeptname ,tf.inputUser ,tf.gname ,tf.id ,tf.gsex "
// +",tf.gtelephone ,tf.address ,tf.inputDate "
// +",tf.fkRegionnameall ,tf.firstDate "
// +",tf.ifSpend ,tf.spdeptName "
// +" from TbFitment as tf";
file://查询条件
String qrycondition="";
if (fitid.length()>0)
qrycondition += " and ;
}
UserFace uf = new UserFace(req);
uf.setOnePage(15);
uf.url="/requests/RequestSearchListAction.do";
List ltFitmentSearch = null;
int record = 0;
record = ((Integer)hsBean.dbSession.iterate("select count(*) from TbFitmentSearch tf where 1=1"+qrycondition).next()).intValue();
uf.PageNum= Math.abs(record/uf.getOnePage());
Query q = hsBean.dbSession.createQuery(HQLStr);
// q.setFirstResult(uf.getOnePage()*(uf.CurPage-1));//起始记录的位置
q.setFirstResult(uf.getStartRecord());
q.setMaxResults(uf.getOnePage());//一页显示的数量
ltFitmentSearch = q.list();
req.setAttribute("userface",uf);
req.setAttribute("ltFitmentSearch",ltFitmentSearch);
return actionMapping.findForward("requestSearchOK");
}
}
分页显示 jsp 页面代码:
<%@ include file="../common/include_taglibs.jsp" %>
<%@ include file="../common/include_charset.jsp" %>
<link href="../css/eall2002.css" rel="stylesheet" type="text/css">
<html:html>
<head>
<title>
billStoreList
</title>
</head>
<body bgcolor="#ffffff">
<h1>
装修需求查询·结果
</h1>
<bean:write name="userface" filter="false" property="content"/>
<table border='0' cellspacing='1' cellpadding='0'>
<logic:iterate >详细</html:link></td>
</tr>
</logic:iterate>
</table>
</body>
</html:html>