自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

淺談Struts2分頁的實(shí)現(xiàn)與代碼實(shí)例

開發(fā) 后端
初識struts2,寫完了分頁做下總結(jié),精簡代碼,方便大家。做分頁的好處在于不用重復(fù)調(diào)用數(shù)據(jù)庫,保證安全。

關(guān)于Struts2分頁其實(shí)有多種實(shí)現(xiàn)方式,主要看他的實(shí)現(xiàn)效率,目前流行的主要是三級分頁,從數(shù)據(jù)庫中讀出的數(shù)據(jù)暫時(shí)存放到table中,不用再次重復(fù)調(diào)用數(shù)據(jù)庫操作,這樣會降低程序的風(fēng)險(xiǎn)

Struts2分頁DAO:

public List getList(int pageSize, int pageNow) {


    //獲取分頁數(shù)據(jù)
    List list = * ;
     //我用的sqlserver
    String sql = "select top 10 * from test
where username like '%badpeas%' and id not in
(select top 0 id from test order by id)
order by id";
    return list;
}


public int getCount() {

    //我用的sqlserver
     String sql = "select count(*) from region where username like '%badpeas%'";
    //得到總數(shù)據(jù)條數(shù)
    int count = *;
    return count;
}

================================
Test類(封裝數(shù)據(jù))

public class Test(){
    private int id;
    private String username;
    private password;
    //省略seter, geter方法.
}


================================
show.jsp



   
       
       
       
   

   

       
       
       
   

NO姓名密碼
.







上一頁
上一頁
下一頁
下一頁
   [page: /]

================================
ShowAction.java

private int pageNow = 1 ; //初始化為1,默認(rèn)從第一頁開始顯示
private int pageSize = 5 ; //每頁顯示5條記錄
private int count; //總頁數(shù)
private List testList;

//省略seter, geter

public String execute() throws Exception {
count = (dao.getCount()-1)/pageSize+1; //得到總頁數(shù)
testList = dao.getList(pageSize, pageNow); //得到list
if (testList == null)
testList = new ArrayList();
return SUCCESS;
}

OK了,分頁就這樣了,我只寫了關(guān)鍵部分代碼,如果對于struts2配置上有任何疑惑,請看Struts2基礎(chǔ)文章,關(guān)于本代碼是從實(shí)際應(yīng)用中截取出來的,如有遺漏或者疑問請及時(shí)聯(lián)系本人.

【編輯推薦】

  1. 在Eclipse中開發(fā)struts應(yīng)用程序
  2. 手把手教你在Eclipse中配置開發(fā)Struts
  3. Eclipse下開發(fā)struts完整解決亂碼問題
  4. Struts相關(guān)背景介紹
  5. 使用Easy Struts for Eclipse開發(fā)Struts
責(zé)任編輯:張燕妮 來源: 百度空間
相關(guān)推薦

2012-04-25 10:14:40

JavaStruts

2009-06-04 08:01:25

Struts2攔截器原理

2009-07-03 09:35:57

Struts2 JSP

2010-09-30 13:37:34

DB2分頁

2009-06-04 08:45:01

Struts2下載

2009-06-08 16:44:00

Struts2文件上傳

2009-06-04 09:41:50

struts2上傳文件

2011-05-03 09:40:58

iBatis

2011-06-28 09:14:23

Struts 2WebWork

2009-06-05 09:52:25

struts分頁Hibernate

2009-06-05 09:58:20

struts2驗(yàn)證用戶注冊

2009-07-17 17:45:56

iBATIS Spri

2011-04-28 09:52:04

Struts2

2011-05-13 09:53:02

strutsAjax

2011-07-18 14:43:40

JSON模擬加載初析

2009-07-29 09:54:34

struts2和str

2009-06-08 16:44:00

struts2 ogn

2009-06-05 10:43:29

struts2 checheckbox實(shí)例

2009-06-25 15:11:28

Struts2教程Struts2程序

2013-05-22 10:28:19

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號