JSPページング技術オリジナル、テストOK、データベースがどれだけのデータがあっても、思う存分めくることができます!
<span style="font-family: Arial, Helvetica, sans-serif;">package accp.hhs.util;</span>
public class PageMoed {
private int currentIndex; //
private int rowSize; //
private int sunPage; //
private int beginRow; //
private int startIndex; //
private String order; //
public String getOrder() {
return order;
}
public void setOrder(String order) {
this.order = order;
}
/**
*
* @return
*/
public int getStartIndex() {
for(int i=1;i<=this.getSunPage();i+=8){
if(this.getCurrentIndex()>=i&&this.getCurrentIndex()<i+9){
startIndex=i;
break;
}
}
return startIndex;
}
/**
*
* @return
*/
public int getBeginRow() {
// , -1*
beginRow=(currentIndex-1)*rowSize;
return beginRow;
}
public void setBeginRow(int beginRow) {
this.beginRow = beginRow;
}
public int getSunPage() {
return sunPage;
}
//
public void setSunPage(int sunRow) {
int temp=0;
temp=(sunRow%this.getRowSize()==0)?sunRow/this.getRowSize():sunRow/this.getRowSize()+1;
System.out.println(" : "+temp+" :"+this.getRowSize());
this.sunPage=temp;
}
/**
*
* @return
*/
public int getCurrentIndex() {
return currentIndex;
}
public void setCurrentIndex(String currentIndex) {
// =1
if("".equals(currentIndex)||null==currentIndex||!IsNum.isNum(currentIndex)){
currentIndex="1";
}
int currentIndexs=Integer.parseInt(currentIndex);
//
if(currentIndexs>=this.getSunPage()){
currentIndexs=this.getSunPage();
}
if(currentIndexs<=0){
currentIndexs=1;
}
this.currentIndex = currentIndexs;
}
/**
*
* @return
*/
public int getRowSize() {
if(rowSize<=0){
rowSize=2;
}
return rowSize;
}
public void setRowSize(int rowSize) {
this.rowSize = rowSize;
}
}
</pre><p>JSP , OK, , !</p><p> ! , , ! 。。。。。。。。</p><p> </p><p></p><pre name="code" class="html"><div>
<p>
<a href="${pageContext.request.contextPath}/EmpSerive.do?flag=showEmp¤tIndex=${currentIndex-1}">
</a>
【${currentIndex}/${totalPage}】
<c:forEach var="i" begin="${satrtIndex}" end="${satrtIndex+9}">
<a href="${pageContext.request.contextPath}/EmpSerive.do?flag=showEmp¤tIndex=${i}">
<c:if test="${currentIndex==i}"> <font color='red'> ${i} </font> </c:if>
<c:if test="${currentIndex!=i}">${i} </c:if>
</a>
</c:forEach>
<a href="${pageContext.request.contextPath}/EmpSerive.do?flag=showEmp¤tIndex=${currentIndex+1}">
</a>
<input type="text" size="2" id="valuePage"/>
<a href="javascript:PageIndex()"> </a>
</p>
<%-- --%>
<script type="text/javascript">
function PageIndex(){
var pagev=document.getElementById("valuePage");
location.href="${pageContext.request.contextPath}/EmpSerive.do?flag=showEmp¤tIndex="+pagev.value;
}
</script>
</div>
よし!実现の种类の方法も贴り出して、见て分からないで私のせいにしないでください、私がテストをして反射のメカニズムを使ったため、私に见せて私は急に理解できませんでした!ははは、必要なものを見てください.の
/**
* hql
*/
@Override
public List<T> getPage(String hql, Object[] paramters, PageMoed pageMeod) {
Query query=sessionFactory.getCurrentSession().createQuery(hql);
if(paramters!=null){
for(int i=0;i<paramters.length;i++){
query.setParameter(i,paramters[i]);
}
}
query.setFirstResult(pageMeod.getBeginRow()).setMaxResults(pageMeod.getRowSize());
return (List<T>)query.list();
}
/**
*
*/
@Override
public List<T> getPage(T e, PageMoed pageMeod) throws Exception {
Class cla=e.getClass();
String tableName=cla.getSimpleName();
Field[] field=cla.getDeclaredFields();//
//SQL
StringBuffer sb=new StringBuffer();
sb.append(" where 1=1 ");
//List<Object> listValue=new ArrayList<Object>();
//?
for(int i=0;i<field.length;i++){
Field f=field[i];
f.setAccessible(true);
Object obj=f.get(e); //
if(obj instanceof Set){
System.out.println(" Set.....");
((Set) obj).clear();
}else
// ?
if(!"".equals(obj)&&null!=obj){//
sb.append(" and "+f.getName()+"= "+obj);
//listValue.add(obj);
}
}
//
if(pageMeod.getOrder()!=null){
sb.append(" "+pageMeod.getOrder());
}
String hql="from "+tableName+" "+sb.toString();
System.out.println("HQL: "+hql);
Query query=sessionFactory.getCurrentSession().createQuery(hql);
//
List<T> liste=(List<T>)query.setFirstResult(pageMeod.getBeginRow()).setMaxResults(pageMeod.getRowSize()).list();
//
return liste;
}
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">