国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
SSH分頁(yè)技術(shù)
先是一個(gè)page的bean:
package com.leatherstore.other;

public class Page {

// 是否有上一頁(yè)
private boolean hasPrePage;

//是否有下一頁(yè)

private boolean hasNextPage;

// 每頁(yè)的數(shù)量
private int everyPage;

// 總頁(yè)數(shù)

private int totalPage;

//當(dāng)前頁(yè)
private int currentPage;

// 起始點(diǎn)
private int beginIndex;

// 總記錄數(shù)
private int totalCount;


//@return totalCount

public int getTotalCount() {
return totalCount;
}

//@param totalCount 要設(shè)置的 totalCount

public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}

//The default constructor
public Page(){

}

// construct the page by everyPage
public Page(int everyPage){
this.everyPage = everyPage;
}

//The whole constructor
public Page(boolean hasPrePage, boolean hasNextPage,
int everyPage, int totalPage,
int currentPage, int beginIndex,int totalCount) {
this.hasPrePage = hasPrePage;
this.hasNextPage = hasNextPage;
this.everyPage = everyPage;
this.totalPage = totalPage;
this.currentPage = currentPage;
this.beginIndex = beginIndex;
this.totalCount = totalCount;
}


public int getBeginIndex() {
return beginIndex;
}


public void setBeginIndex(int beginIndex) {
this.beginIndex = beginIndex;
}


public int getCurrentPage() {
return currentPage;
}


public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}


public int getEveryPage() {
return everyPage;
}


public void setEveryPage(int everyPage) {
this.everyPage = everyPage;
}


public boolean getHasNextPage() {
return hasNextPage;
}


public void setHasNextPage(boolean hasNextPage) {
this.hasNextPage = hasNextPage;
}


public boolean getHasPrePage() {
return hasPrePage;
}


public void setHasPrePage(boolean hasPrePage) {
this.hasPrePage = hasPrePage;
}


public int getTotalPage() {
return totalPage;
}


public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
}
然后構(gòu)建一個(gè)page的工廠PageUtil:
package com.leatherstore.other;

public class PageUtil {

// Use the origin page to create a new page


public static Page createPage(Page page, int totalRecords) {
return createPage(page.getEveryPage(), page.getCurrentPage(),
totalRecords);
}


//the basic page utils not including exception handler


public static Page createPage(int everyPage, int currentPage,
int totalRecords) {
everyPage = getEveryPage(everyPage);
currentPage = getCurrentPage(currentPage);
int beginIndex = getBeginIndex(everyPage, currentPage);
int totalPage = getTotalPage(everyPage, totalRecords);
boolean hasNextPage = hasNextPage(currentPage, totalPage);
boolean hasPrePage = hasPrePage(currentPage);

return new Page(hasPrePage, hasNextPage, everyPage, totalPage,
currentPage, beginIndex, totalRecords);
}

private static int getEveryPage(int everyPage) {
return everyPage == 0 ? 10 : everyPage;
}

private static int getCurrentPage(int currentPage) {
return currentPage == 0 ? 1 : currentPage;
}

private static int getBeginIndex(int everyPage, int currentPage) {
return (currentPage - 1) * everyPage;
}

private static int getTotalPage(int everyPage, int totalRecords) {
int totalPage = 0;

if (totalRecords % everyPage == 0)
totalPage = totalRecords / everyPage;
else
totalPage = totalRecords / everyPage + 1;

return totalPage;
}

private static boolean hasPrePage(int currentPage) {
return currentPage == 1 ? false : true;
}

private static boolean hasNextPage(int currentPage, int totalPage) {
return currentPage == totalPage || totalPage == 0 ? false : true;
}

}
然后建一個(gè)專用的bean:
package com.leatherstore.hibernate.domain;

import java.util.List;

import com.leatherstore.other.Page;

public class Result {
private Page page; //分頁(yè)信息
private List content; //每頁(yè)顯示的集合

//The default constructor
public Result() {
super();
}


//The constructor using fields
public Result(Page page, List content) {
this.page = page;
this.content = content;
}


public List getContent() {
return content;
}


public Page getPage() {
return page;
}


public void setContent(List content) {
this.content = content;
}


public void setPage(Page page) {
this.page = page;
}
}

然后在數(shù)據(jù)訪問(wèn)層寫(xiě)兩個(gè)方法:
ProductDAO:
public List getProductByPage(Page page);
public int getProductCount(); //返回?cái)?shù)據(jù)的總數(shù)
ProductDAO的接口實(shí)現(xiàn)ProductDAOImpl:
//為了在spring里統(tǒng)一編程風(fēng)格:我用的回調(diào)的方法
public List getProductByPage(final Page page) {
return this.getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query=session.createQuery("from Productinfo");
query.setFirstResult(page.getBeginIndex()); //hibernate分頁(yè)的精髓 呵呵
query.setMaxResults(page.getEveryPage());
return query.list();
}
});
}

public int getProductCount() {
List list=this.getHibernateTemplate().find("select count(*) from Productinfo");
return ((Integer)list.iterator().next()).intValue();
}
然后是業(yè)務(wù)層:
IProduct:
public Result listProduct(Page page);
然后IProduct接口的實(shí)現(xiàn):IProductImpl:
private ProductDAO productDAO;
public void setProductDAO(ProductDAO productDAO){
this.productDAO=productDAO;
}

public Result listProduct(Page page) {
int totalRecords = this.productDAO.getProductCount();
page = PageUtil.createPage(page, totalRecords);
List products = this.productDAO.getProductByPage(page);
return new Result(page, products);
}
然后再代理層:
ProductProxy:
IProduct pro=(IProduct)AppContext.getInstance().getappcontext().getBean("productServicewithTran");

public Result productlist(Page page){
try{
return pro.listProduct(page);
}catch(DataAccessException ex){
ex.printStackTrace();
return null;
}
}
呵呵 終于到productAction啦
顯示前方法的代碼
Page page = new Page(); //實(shí)例化一個(gè)page對(duì)象
page.setEveryPage(10); //設(shè)置每頁(yè)顯示的條數(shù)
page.setCurrentPage(1); //為第一頁(yè)
Result result = pdp.productlist(page);
request.setAttribute("page", pageinfo);
request.setAttribute("productlist", list);
return mapping.findForward("showProduct");
接著就是jsp頁(yè)面了
<logic:iterate id="product" name="productlist">
//中間迭代所要顯示的數(shù)據(jù)
</logic:iterate>
<tr>
<td width="80" height="30"> </td>
<logic:equal value="true" name="page" property="hasPrePage">
<td width="150" height="30"><div align="right"><a href="../product.do?method=showProductByTag&index=first&msg=${msg }">首頁(yè)</a></div></td>
<td width="80" height="30"><div align="center"><a href="../product.do?method=showProductByTag&index=prew&pageno=${page.currentPage -1}&msg=${msg }">上一頁(yè)</a></div></td>
</logic:equal>
<logic:notEqual value="true" name="page" property="hasPrePage">
<td width="150" height="30"><div align="right">首頁(yè)</div></td>
<td width="80" height="30"><div align="center">上一頁(yè)</div></td>
</logic:notEqual>
<logic:equal value="true" name="page" property="hasNextPage">
<td width="80" height="30"><div align="center"><a href="../product.do?method=showProductByTag&index=next&pageno=${page.currentPage +1 }&msg=${msg }">下一頁(yè)</a></div></td>
<td width="80" height="30"><div align="center"><a href="../product.do?method=showProductByTag&index=end&pageno=${page.totalPage }&msg=${msg }">尾頁(yè)</a></div></td>
</logic:equal>
<logic:notEqual value="true" name="page" property="hasNextPage">
<td width="80" height="30"><div align="center">下一頁(yè)</div></td>
<td width="80" height="30"><div align="center">尾頁(yè)</div></td>
</logic:notEqual>
<td height="30" colspan="3"><div align="center">頁(yè)次${page.currentPage }/${page.totalPage }   共${page.totalCount }條記錄</div> <div align="center"></div></td>
</tr>
可以顯示相應(yīng)的頁(yè)面信息
然后productAction里面的showProductByTag代碼如下:
Page page = new Page();
page.setEveryPage(10);
String pagemark = request.getParameter("goto");
if (pagemark == null) {
String state = request.getParameter("index");
String pageno = request.getParameter("pageno");
System.out.println("pageno=" + pageno);
if ("first".equals(state)) {
page.setCurrentPage(1);
Result result = pdp.productlist(page);
request.setAttribute("page", result.getPage());
request.setAttribute("productlist", result.getContent());
} else if ("prew".equals(state)) {
page.setCurrentPage(Integer.parseInt(pageno));
Result result = pdp.productlist(page);
request.setAttribute("page", result.getPage());
request.setAttribute("productlist", result.getContent());
} else if ("next".equals(state)) {
page.setCurrentPage(Integer.parseInt(pageno));
Result result = pdp.productlist(page);
request.setAttribute("page", result.getPage());
request.setAttribute("productlist", result.getContent());
} else if ("end".equals(state)) {
page.setCurrentPage(Integer.parseInt(pageno));
Result result = pdp.productlist(page);
request.setAttribute("page", result.getPage());
request.setAttribute("productlist", result.getContent());
}
} else {
page.setCurrentPage(Integer.parseInt(pagemark));
Result result = pdp.productlist(page);
request.setAttribute("page", result.getPage());
request.setAttribute("productlist", result.getContent()); 
}
return mapping.findForward("showProduct");

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
WEB開(kāi)發(fā)中Struts分頁(yè)算法
Freemarker分頁(yè) - 石礫 - JavaEye技術(shù)網(wǎng)站
S2SH項(xiàng)目實(shí)現(xiàn)分頁(yè)功能
ssh2分頁(yè)解決方案
s2sh 底層封裝(增,刪,改,查,分頁(yè))
JDBC 學(xué)習(xí)筆記(一)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服