<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-6  評(píng)論-38  文章-40  trackbacks-0

    ?

    Pager類:

    ?

    package ?com.zeroidea.common;

    ?

    public ? class ?Pager? {

    ???????????????????????
    private ? int ?totalRows;??? // ?總行數(shù)????

    ???????????????????????
    private ? int ?pageSize;???? // ?單頁(yè)數(shù)據(jù)項(xiàng)

    ???????????????????????
    private ? int ?currentPage; // ?當(dāng)前頁(yè)號(hào)

    ???????????????????????
    private ? int ?totalPages;? // ?總頁(yè)數(shù)

    ???????????????????????
    private ? int ?startRows;?? // ?當(dāng)前頁(yè)在數(shù)據(jù)庫(kù)中記錄位置

    ???????????????????????

    ???????????????????????
    public ?Pager() {??

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    public ?Pager( int ?totalRows) {? // ?指定總行數(shù)據(jù)

    ????????????????????????
    this .setPageSize( 10 );??? // ?每頁(yè)?10條數(shù)據(jù)?

    ????????????????????????
    this .setTotalRows(totalRows);???

    ?

    ????????????????????????
    int ?pages? = ?totalRows / pageSize;

    ????????????????????????
    if ?((totalRows % pageSize)? > ? 0 ) {

    ????????????????????????????pages
    ++ ;

    ????????????????????????}


    ????????????????????????
    this .setTotalPages(pages);

    ????????????????????????

    ????????????????????????
    this .setStartRows( 0 );

    ????????????????????????
    this .setCurrentPage( 1 );?

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?
    @return ?the?currentPage

    ????????????????????????
    */


    ???????????????????????
    public ? int ?getCurrentPage()? {

    ????????????????????????
    return ?currentPage;

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?
    @param ?currentPage?the?currentPage?to?set

    ????????????????????????
    */


    ???????????????????????
    public ? void ?setCurrentPage( int ?currentPage)? {

    ????????????????????????
    this .currentPage? = ?currentPage;

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?
    @return ?the?pageSize

    ????????????????????????
    */


    ???????????????????????
    public ? int ?getPageSize()? {

    ????????????????????????
    return ?pageSize;

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?
    @param ?pageSize?the?pageSize?to?set

    ????????????????????????
    */


    ???????????????????????
    public ? void ?setPageSize( int ?pageSize)? {

    ????????????????????????
    this .pageSize? = ?pageSize;

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?
    @return ?the?startRows

    ????????????????????????
    */


    ???????????????????????
    public ? int ?getStartRows()? {

    ????????????????????????
    return ?startRows;

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?
    @param ?startRows?the?startRows?to?set

    ????????????????????????
    */


    ???????????????????????
    public ? void ?setStartRows( int ?startRows)? {

    ????????????????????????
    this .startRows? = ?startRows;

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?
    @return ?the?totalPages

    ????????????????????????
    */


    ???????????????????????
    public ? int ?getTotalPages()? {

    ????????????????????????
    return ?totalPages;

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?
    @param ?totalPages?the?totalPages?to?set

    ????????????????????????
    */


    ???????????????????????
    public ? void ?setTotalPages( int ?totalPages)? {

    ????????????????????????
    this .totalPages? = ?totalPages;

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?
    @return ?the?totalRows

    ????????????????????????
    */


    ???????????????????????
    public ? int ?getTotalRows()? {

    ????????????????????????
    return ?totalRows;

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?
    @param ?totalRows?the?totalRows?to?set

    ????????????????????????
    */


    ???????????????????????
    public ? void ?setTotalRows( int ?totalRows)? {

    ????????????????????????
    this .totalRows? = ?totalRows;

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?第一頁(yè)

    ????????????????????????
    */


    ???????????????????????
    public ? void ?fristPage() {

    ????????????????????????
    this .setCurrentPage( 1 );

    ????????????????????????
    this .setStartRows( 0 );

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?前一頁(yè)

    ????????????????????????
    */


    ???????????????????????
    public ? void ?previousPage() {

    ????????????????????????
    int ?nowPage? = ? this .getCurrentPage();?

    ????????????????????????
    if ?(nowPage? == ? 1 ) {

    ????????????????????????????
    return ;

    ????????????????????????}


    ???????????????????????
    this .setCurrentPage( -- nowPage);

    ????????????????????????
    this .setStartRows((nowPage? - ? 1 )? * ? this .getPageSize());

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?后一頁(yè)

    ????????????????????????
    */


    ???????????????????????
    public ? void ?nextPage() {

    ????????????????????????
    int ?nowPage? = ? this .getCurrentPage();

    ????????????????????????
    if ?(nowPage? == ? this .getTotalPages()) {

    ????????????????????????????
    this .lastPage();

    ????????????????????????????
    return ;

    ????????????????????????}


    ????????????????????????
    this .setCurrentPage(nowPage? + ? 1 );

    ????????????????????????
    this .setStartRows(nowPage? * ? this .getPageSize());

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?最后一頁(yè)

    ????????????????????????
    */


    ???????????????????????
    public ? void ?lastPage() {

    ????????????????????????
    this .setCurrentPage( this .getTotalPages());

    ????????????????????????
    this .setStartRows(( this .getTotalPages()? - ? 1 )? * ? this .getPageSize());

    ???????????????????????}


    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?刷新頁(yè)

    ????????????????????????*?
    @param ?currentPage

    ????????????????????????
    */


    ???????????????????????
    public ? void ?refreshPage( int ?currentPage) {

    ????????????????????????
    this .setCurrentPage(currentPage);???

    ????????????????????????
    this .setStartRows((currentPage? - ? 1 )? * ? this .getPageSize());

    ????????????????????????
    if ?(currentPage? > ? this .getTotalPages()) {

    ????????????????????????????
    this .lastPage();

    ????????????????????????}


    ???????????????????????}


    }


    ?

    ?

    數(shù)據(jù)查詢:

    ?

    ???????????????????????

    ???????????????????????
    /**

    ????????????????????????*?取得總數(shù)據(jù)行??:有更簡(jiǎn)單的方法請(qǐng)分享

    ????????????????????????
    */


    ???????????????????????
    public ? int ?selectDataRows()? {

    ????????????????????????
    int ?rows? = ? 0 ;

    ????????????????????????List?list?
    = ? null ;

    ????????????????????????Session?session?
    = ? null ;

    ????????????????????????Transaction?transaction?
    = ? null ;

    ????????????????????????Query?query?
    = ? null ;

    ????????????????????????
    try ? {

    ????????????????????????????session?
    = ?SessionFactory.currentSession();

    ????????????????????????????transaction?
    = ?session.beginTransaction();

    ????????????????????????????query?
    = ?session

    ????????????????????????????????????.createQuery(
    " select?msg?from?Msg?as?msg " );

    ????????????????????????????list?
    = ?query.list();

    ????????????????????????????rows?
    = ?list.size();

    ????????????????????????????transaction.commit();

    ????????????????????????????session.close();

    ????????????????????????}
    ? catch ?(Exception?excp)? {

    ????????????????????????????session.close();

    ????????????????????????}


    ?

    ????????????????????????
    return ?rows;

    ???????????????????????}


    ???????????????????????

    ?

    ?

    ?

    ???????????????????????
    /**

    ????????????????????????*?分頁(yè)查詢數(shù)據(jù)

    ????????????????????????*?

    ????????????????????????*?
    @param ?pager?

    ????????????????????????*?
    @return ?0?1?0:?Success?1:?Fail

    ????????????????????????
    */


    ???????????????????????
    public ?List?selectData(Pager?pager)? {

    ????????????????????????List?list?
    = ? null ;

    ????????????????????????Session?session?
    = ? null ;

    ????????????????????????Transaction?transaction?
    = ? null ;

    ????????????????????????Query?query?
    = ? null ;

    ????????????????????????

    ????????????????????????
    try ? {

    ????????????????????????????session?
    = ?SessionFactory.currentSession();

    ????????????????????????????transaction?
    = ?session.beginTransaction();

    ????????????????????????????query?
    = ?session.createQuery( " select?msg?from?Msg?as?msg?order?by?msg.msgId?desc " );

    ????????????????????????????query.setFirstResult(pager.getStartRows());?
    // ?設(shè)置起始行

    ????????????????????????????query.setMaxResults(pager.getPageSize());???
    // ?設(shè)置取數(shù)據(jù)行數(shù)

    ????????????????????????????list?
    = ?query.list();

    ????????????????????????????transaction.commit();

    ????????????????????????????session.close();

    ????????????????????????}
    ? catch ?(Exception?excp)? {

    ????????????????????????????session.close();

    ????????????????????????}


    ????????????????????????
    return ?list;

    ???????????????????????}


    ?

    ?

    ?

    Action?控制:

    ?

    ???????????????????????
    /**

    ????????????????????????*?查詢?方法,,按分頁(yè)查詢

    ????????????????????????*?

    ????????????????????????*?
    @param ?mapping

    ????????????????????????*?
    @param ?form

    ????????????????????????*?
    @param ?request

    ????????????????????????*?
    @param ?response

    ????????????????????????*?
    @return

    ????????????????????????
    */


    ???????????????????????
    public ? void ?selectData(ActionMapping?mapping,?ActionForm?form,

    ????????????????????????????HttpServletRequest?request,?HttpServletResponse?response)?
    {

    ????????????????????????List?list?
    = ? null ;

    ????????????????????????
    int ?currentPage? = ? 1 ;

    ????????????????????????MsgForm?msgForm?
    = ?(MsgForm)?form;

    ????????????????????????

    ????????????????????????String?pageMethod?
    = ?request.getParameter( " pageMethod " );????????? // ?存放請(qǐng)求頁(yè)方法

    ????????????????????????String?currentPageTemp?
    = ?request.getParameter( " currentPage " );??? // ?存放當(dāng)前頁(yè)

    ????????????????????????

    ????????????????????????OperTable?operTable?
    = ? new ?OperTable();?????????????????????????? // ?操作表類

    ????????????????????????Pager?pager?
    = ? new ?Pager(operTable.selectDataRows());???????????? // ?頁(yè)面控制類

    ????????????????????????

    ????????????????????????

    ????????????????????????
    if ?(currentPageTemp? == ? null ) {

    ????????????????????????????pager.setCurrentPage(
    1 );

    ????????????????????????}
    ? else ? {

    ????????????????????????????currentPage?
    = ?Integer.parseInt(currentPageTemp);

    ????????????????????????}


    ????????????????????????

    ????????????????????????pager.setCurrentPage(currentPage);

    ????????????????????????

    ????????????????????????
    if ?(pageMethod? == ? null ) {

    ????????????????????????????pager.fristPage();??????
    // ?到首頁(yè)

    ????????????????????????????System.out.println(
    " 首頁(yè) " );

    ????????????????????????}
    else {

    ????????????????????????????
    if ?(pageMethod.equals( " previousPage " )) {

    ????????????????????????????????pager.previousPage();???
    // ?到前一頁(yè)

    ????????????????????????????????System.out.println(
    " 前一頁(yè) " );

    ????????????????????????????}
    ? else ? if ?(pageMethod.equals( " nextPage " )) {

    ????????????????????????????????pager.nextPage();???????
    // ?到后一頁(yè)

    ????????????????????????????????System.out.println(
    " 后一頁(yè) " );

    ????????????????????????????}
    ? else ? if ?(pageMethod.equals( " lastPage " )) {

    ????????????????????????????????pager.lastPage();???????
    // ?到尾頁(yè)

    ????????????????????????????????System.out.println(
    " 尾頁(yè) " );

    ????????????????????????????}
    else ? if ?(pageMethod.equals( " refreshPage " )) {

    ????????????????????????????????pager.refreshPage(currentPage);

    ????????????????????????????????System.out.println(currentPage);

    ????????????????????????????????System.out.println(
    " 刷新頁(yè) " );

    ????????????????????????????}
    ? else ? {

    ????????????????????????????????pager.fristPage();??????
    // ?到首頁(yè)

    ????????????????????????????????System.out.println(
    " 首頁(yè) " );

    ????????????????????????????}


    ????????????????????????}


    ????????????????????????

    ????????????????????????request.setAttribute(
    " pager " ,?pager);

    ????????????????????????request.setAttribute(
    " msgdata " ,?list);

    ????????????????????????request.setAttribute(
    " info " ,? " 已查詢數(shù)據(jù) " );

    ????????????????????????msgForm.reset(mapping,?request);

    ???????????????????????}


    ?

    ?

    JSP顯示分頁(yè):?href這樣用:

    ?

    ????????????????????????????????????
    < logic:present?name = " pager " >

    ????????????????????????????????????????
    < a?href = " msg.do?method=select&pageMethod=fristPage&currentPage=<bean:write?name='pager'?property='currentPage'/> " > 首頁(yè) </ a >

    ????????????????????????????????????????
    < a?href = " msg.do?method=select&pageMethod=previousPage&currentPage=<bean:write?name='pager'?property='currentPage'/> " > 前一頁(yè) </ a >

    ????????????????????????????????????????
    < a?href = " msg.do?method=select&pageMethod=nextPage&currentPage=<bean:write?name='pager'?property='currentPage'/> " > 后一頁(yè) </ a >

    ????????????????????????????????????????
    < a?href = " msg.do?method=select&pageMethod=lastPage&currentPage=<bean:write?name='pager'?property='currentPage'/> " > 尾頁(yè) </ a >

    ????????????????????????????????????????共有
    < span? class = " font-normal-red " >< bean:write?name = " pager " ?property = " totalRows " /></ span > 條記錄,當(dāng)前第 < span? class = " font-normal-red " >< bean:write?name = " pager " ?property = " currentPage " /></ span > 頁(yè),共有 < span? class = " font-normal-red " >< bean:write?name = " pager " ?property = " totalPages " /></ span > ?頁(yè)

    ????????????????????????????????????
    </ logic:present >

    ?

    < html:link > ?這樣用

    ?

    ??????????????????
    < logic:present?name = " pager " >

    ?????????????????????
    < html:link?page = " /msg.do?method=select&pageMethod=fristPage " ?paramId = " currentPage " ?paramName = " pager " ?paramProperty = " currentPage " > 首頁(yè) </ html:link >

    ?????????????????????
    < html:link?page = " /msg.do?method=select&pageMethod=previousPage " ?paramId = " currentPage " ?paramName = " pager " ???paramProperty = " currentPage " > 前一頁(yè) </ html:link >

    ?????????????????????
    < html:link?page = " /msg.do?method=select&pageMethod=nextPage " ????paramId = " currentPage " ?paramName = " pager " ???paramProperty = " currentPage " > 下一頁(yè) </ html:link >

    ?????????????????????
    < html:link?page = " /msg.do?method=select&pageMethod=lastPage " ????paramId = " currentPage " ?paramName = " pager " ???paramProperty = " currentPage " > 尾頁(yè) </ html:link >

    ?????????????????????共有

    ?????????????????????
    < span? class = " font-normal-red " >< bean:write?name = " pager " ?property = " totalRows " ? />

    ?????????????????????
    </ span > 條記錄,當(dāng)前第 < span? class = " font-normal-red " >< bean:write?name = " pager " ?property = " currentPage " ? />

    ?????????????????????
    </ span > 頁(yè),共有 < span? class = " font-normal-red " >< bean:write?name = " pager " ?property = " totalPages " ? />

    ?????????????????????
    </ span > ?頁(yè)

    ?????????????????????????????????????????????????????????????????????????????????????????????????
    </ logic:present >
    posted on 2006-11-30 16:26 一手的小窩窩 閱讀(168) 評(píng)論(0)  編輯  收藏 所屬分類: JAVA
    主站蜘蛛池模板: 国产三级免费电影| 国产成人精品免费视频大全麻豆 | 亚洲国产高清视频| www免费黄色网| 亚洲午夜激情视频| 人人鲁免费播放视频人人香蕉| 成人免费毛片观看| 亚洲午夜福利在线视频| 青春禁区视频在线观看直播免费| 亚洲精品免费在线视频| 曰曰鲁夜夜免费播放视频| 亚洲日本乱码一区二区在线二产线 | 国产91免费在线观看| 亚洲理论电影在线观看| 久久久精品午夜免费不卡| 久久精品国产精品亚洲蜜月| 18禁超污无遮挡无码免费网站| 久久香蕉国产线看观看亚洲片| 免费国产黄网站在线观看 | 成人看的午夜免费毛片| 亚洲AV噜噜一区二区三区| 亚洲AV之男人的天堂| 十八禁在线观看视频播放免费| 色拍自拍亚洲综合图区| aa级一级天堂片免费观看| 国产精品亚洲一区二区无码 | 国产午夜免费高清久久影院| 亚洲尹人香蕉网在线视颅| 美女裸身网站免费看免费网站 | 精品久久亚洲中文无码| 午夜一区二区免费视频| 一级女性全黄久久生活片免费| 亚洲国产精品福利片在线观看| 国产精品入口麻豆免费观看| 亚洲av无码片vr一区二区三区| 亚洲真人无码永久在线| 嘿嘿嘿视频免费网站在线观看| 亚洲AV色无码乱码在线观看| 亚洲国产精品福利片在线观看| 成人无遮挡毛片免费看| 99久久免费国产精精品|