日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

ssh框架分页显示问题

發(fā)布時(shí)間:2024/1/17 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ssh框架分页显示问题 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

??? 對(duì)于ssh框架來(lái)說(shuō)的話分頁(yè),主要的思想就是dao層完成對(duì)數(shù)據(jù)庫(kù)的操作,service層對(duì)業(yè)務(wù)進(jìn)行管理,action對(duì)頁(yè)面進(jìn)行管理。

分頁(yè)需要的bean。

?

  • import?java.util.List; ?
  • public?class?PageBean?{ ?
  • ?????????private?List?list; ?
  • ????private?int?allRow;//?總記錄數(shù) ?
  • ????private?int?totalPage;//?總頁(yè)數(shù) ?
  • ????private?int?currentPage;//?當(dāng)前頁(yè) ?
  • ????private?int?pageSize;//?每頁(yè)記錄數(shù) ?
  • ???????????private?boolean?isFirstPage;//?是否為第一頁(yè) ?
  • ????private?boolean?isLastPage;//?是否為最后一頁(yè) ?
  • ????private?boolean?hasPreviousPage;//?是否有前一頁(yè) ?
  • ????private?boolean?hasNextPage;//?是否有下一頁(yè) ?
  • ?
  • ????public?List?getList()?{ ?
  • ????????return?list; ?
  • ????} ?
  • ?
  • ????public?void?setList(List?list)?{ ?
  • ????????this.list?=?list; ?
  • ????} ?
  • ?
  • ????public?void?setFirstPage(boolean?isFirstPage)?{ ?
  • ????????this.isFirstPage?=?isFirstPage; ?
  • ????} ?
  • ?
  • ????public?void?setLastPage(boolean?isLastPage)?{ ?
  • ????????this.isLastPage?=?isLastPage; ?
  • ????} ?
  • ?
  • ????public?void?setHasPreviousPage(boolean?hasPreviousPage)?{ ?
  • ????????this.hasPreviousPage?=?hasPreviousPage; ?
  • ????} ?
  • ?
  • ????public?void?setHasNextPage(boolean?hasNextPage)?{ ?
  • ????????this.hasNextPage?=?hasNextPage; ?
  • ????} ?
  • ?
  • ???? ?
  • ?
  • ????public?int?getAllRow()?{ ?
  • ????????return?allRow; ?
  • ????} ?
  • ?
  • ????public?void?setAllRow(int?allRow)?{ ?
  • ????????this.allRow?=?allRow; ?
  • ????} ?
  • ?
  • ????public?int?getTotalPage()?{ ?
  • ????????return?totalPage; ?
  • ????} ?
  • ?
  • ????public?void?setTotalPage(int?totalPage)?{ ?
  • ????????this.totalPage?=?totalPage; ?
  • ????} ?
  • ?
  • ????public?int?getCurrentPage()?{ ?
  • ????????return?currentPage; ?
  • ????} ?
  • ?
  • ????public?void?setCurrentPage(int?currentPage)?{ ?
  • ????????this.currentPage?=?currentPage; ?
  • ????} ?
  • ?
  • ????public?int?getPageSize()?{ ?
  • ????????return?pageSize; ?
  • ????} ?
  • ?
  • ????public?void?setPageSize(int?pageSize)?{ ?
  • ????????this.pageSize?=?pageSize; ?
  • ????} ?
  • ?
  • ???? ?
  • ?
  • ????//?  /**?*//** ?
  • ????//?  ?*?初始化分頁(yè)信息 ?
  • ????//?  ?*/ ?
  • ????public?void?init()?{ ?
  • ????????this.isFirstPage?=?isFirstPage(); ?
  • ????????this.isLastPage?=?isLastPage(); ?
  • ????????this.hasPreviousPage?=?isHasPreviousPage(); ?
  • ????????this.hasNextPage?=?isHasNextPage(); ?
  • ????} ?
  • ?
  • ????//?  /**?*//** ?
  • ????//?  ?*?以下判斷頁(yè)的信息,只需getter方法(is方法)即可 ?
  • ????//?  ?*?@return ?
  • ????//?  ?*/ ?
  • ????//?   ?
  • ????public?boolean?isFirstPage()?{ ?
  • ????????return?currentPage?==?1;//?如是當(dāng)前頁(yè)是第1頁(yè) ?
  • ????} ?
  • ?
  • ????public?boolean?isLastPage()?{ ?
  • ????????return?currentPage?==?totalPage;//?如果當(dāng)前頁(yè)是最后一頁(yè) ?
  • ????} ?
  • ?
  • ????public?boolean?isHasPreviousPage()?{ ?
  • ????????return?currentPage?!=?1;//?只要當(dāng)前頁(yè)不是第1頁(yè) ?
  • ????} ?
  • ?
  • ????public?boolean?isHasNextPage()?{ ?
  • ????????return?currentPage?!=?totalPage;//?只要當(dāng)前頁(yè)不是最后1頁(yè) ?
  • ????}?//?  ?
  • ?
  • ????//?  ?
  • ????//?  /**?*//** ?
  • ????//?  ?*?計(jì)算總頁(yè)數(shù),靜態(tài)方法,供外部直接通過(guò)類(lèi)名調(diào)用 ?
  • ????//?  ?*?@param?pageSize?每頁(yè)記錄數(shù) ?
  • ????//?  ?*?@param?allRow?總記錄數(shù) ?
  • ????//?  ?*?@return?總頁(yè)數(shù) ?
  • ????//?  ?*/ ?
  • ????public?static?int?countTotalPage(final?int?pageSize,?final?int?allRow)?{ ?
  • ????????int?totalPage?=?allRow?%?pageSize?==?0???allRow?/?pageSize?:?allRow ?
  • ????????????????/?pageSize?+?1; ?
  • ????????return?totalPage; ?
  • ????} ?
  • ?
  • ????//?  /**?*//** ?
  • ?????????//?????*這個(gè)方法的邏輯非常關(guān)鍵,如果不弄清的話,在dao層調(diào)用的時(shí)候會(huì)出現(xiàn)不必要的麻煩。 ?
  • ????//?  ?*?計(jì)算當(dāng)前頁(yè)開(kāi)始記錄 ?
  • ????//?  ?*?@param?pageSize?每頁(yè)記錄數(shù) ?
  • ????//?  ?*?@param?currentPage?當(dāng)前第幾頁(yè) ?
  • ????//?  ?*?@return?當(dāng)前頁(yè)開(kāi)始記錄號(hào) ?
  • ????//?  ?*/ ?
  • ????public?static?int?countOffset(final?int?pageSize,?final?int?currentPage)?{ ?
  • ???????? ?
  • ????????int?offset?=?pageSize?*?(currentPage?-?1); ?
  • ????????????????if(offset<=0){ ?
  • ????????????????????return?offset?=?0; ?
  • ????????????????} ?
  • ???????????????????? ?
  • ????????return?offset; ?
  • ????} ?
  • ?
  • ????//?? ?
  • ????//?  /**?*//** ?
  • ????//?  ?*?計(jì)算當(dāng)前頁(yè),若為0或者請(qǐng)求的URL中沒(méi)有"?page=",則用1代替 ?
  • ????//?  ?*?@param?page?傳入的參數(shù)(可能為空,即0,則返回1) ?
  • ????//?  ?*?@return?當(dāng)前頁(yè) ?
  • ????//?  ?*/ ?
  • ????public?static?int?countCurrentPage(int?page)?{ ?
  • ????????final?int?curPage?=?(page?==?0???1?:?page); ?
  • ????????return?curPage; ?
  • ????} ?
  • } ?
  • dao層代碼:

    ?

  • package?test; ?
  • ?
  • import?java.sql.SQLException; ?
  • import?java.util.List; ?
  • ?
  • import?org.hibernate.HibernateException; ?
  • import?org.hibernate.Query; ?
  • import?org.hibernate.Session; ?
  • import?org.springframework.orm.hibernate3.HibernateCallback; ?
  • import?org.springframework.orm.hibernate3.support.HibernateDaoSupport; ?
  • ?
  • public?class?MemberDaoImpl?extends?HibernateDaoSupport?implements?MemberDao?{ ?
  • /*?? ?//實(shí)現(xiàn)的接口自己寫(xiě)就可以了 ? ?
  • ????  ? ?
  • ????  *//**?*//**? ?
  • ????  ?*?分頁(yè)查詢? ?
  • ????  ?*?@param?hql?查詢的條件? ?
  • ????  ?*?@param?offset?開(kāi)始記錄? ?
  • ????  ?*?@param?length?一次查詢幾條記錄? ?
  • ????  ?*?@return? ?
  • ????  ?*//*? ?
  • */ ?
  • ????public?List?queryForPage(final?String?hql,?final?int?offset, ?
  • ????????????final?int?length)?{ ?
  • ????????List?list?=?getHibernateTemplate().executeFind(new?HibernateCallback()?{ ?
  • ????????????public?Object?doInHibernate(Session?session)?throws ?
  • ?
  • ????????????HibernateException,?SQLException?{ ?
  • ????????????????Query?query?=?session.createQuery(hql); ?
  • ????????????????query.setFirstResult(offset); ?
  • ????????????????query.setMaxResults(length); ?
  • ????????????????List?list?=?query.list(); ?
  • ????????????????return?list; ?
  • ????????????} ?
  • ????????}); ?
  • ????????return?list; ?
  • ????} ?
  • ?
  • ????public?int?getAllRowCount(String?hql)?{ ?
  • ????????return?getHibernateTemplate().find(hql).size(); ?
  • ?
  • ????} ?
  • ?
  • } ?
  • action:

    ?

  • public?class?ListAction?extends?ActionSupport?{ ?
  • ????//?通過(guò)applicationContext.xml配置文件注入memberService的值 ?
  • ????private?FenyeService?fenyeservice?; ?
  • ?
  • ????public?void?setFenyeService?(FenyeService?fenyeservice?)?{ ?
  • ????????this.fenyeservice?=?fenyeservice?; ?
  • ????} ?
  • ?????????public?FenyeService??getFenyeService?(FenyeService???fenyeservice?){ ?
  • ???????????????????return?fenyeservice? ?
  • } ?
  • ????private?int?page;//?第幾頁(yè) ?
  • ?
  • ????private?PageBean?pageBean;//?包含分布信息的bean ?
  • ?
  • ????public?int?getPage()?{ ?
  • ????????return?page; ?
  • ????} ?
  • ?
  • ????public?void?setPage(int?page)?{//?若URL中無(wú)此參數(shù),會(huì)默認(rèn)為第1頁(yè) ?
  • ????????this.page?=?page; ?
  • ????} ?
  • ?
  • ????public?PageBean?getPageBean()?{ ?
  • ????????return?pageBean; ?
  • ????} ?
  • ?
  • ????public?void?setPageBean(PageBean?pageBean)?{ ?
  • ????????this.pageBean?=?pageBean; ?
  • ????} ?
  • ?
  • ????@Override ?
  • ????public?String?execute()?throws?Exception?{ ?
  • ????????//?分頁(yè)的pageBean,參數(shù)pageSize表示每頁(yè)顯示記錄數(shù),page為當(dāng)前頁(yè) ?
  • ????????this.pageBean?=?fenyeservice?.queryForPage(3,?page); ?
  • ????????return?SUCCESS; ?
  • ????} ?
  • }?
  • jsp頁(yè)面的話就是<s:iterator value="pagebean.list">迭代標(biāo)簽了.<s:property value="list內(nèi)的名字">

    差不多就這些了。如果還有什么疑問(wèn)的話可以給我留言,我盡快給你答復(fù).

    轉(zhuǎn)載于:https://blog.51cto.com/3504199/921056

    創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

    總結(jié)

    以上是生活随笔為你收集整理的ssh框架分页显示问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。