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

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

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

        明月松間照 清泉石上流


                                            ——— 兵臨城下   貓科動(dòng)物
    posts - 70, comments - 137, trackbacks - 0, articles - 23
      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
    新建表

    DROP?DATABASE?IF?EXISTS?`wjcms`;
    CREATE?DATABASE?`wjcms`?/*!40100?DEFAULT?CHARACTER?SET?gb2312?*/;
    USE?`wjcms`;

    #
    #?
    Table?structure?for?table?t_article
    #

    CREATE?TABLE?`t_article`?(
    ??`a_id`?
    int(11)?NOT?NULL?auto_increment,
    ??`a_sort`?
    int(11)?NOT?NULL?default?'0',
    ??`a_title`?
    varchar(50)?default?NULL,
    ??`a_body`?
    text,
    ??`a_author`?
    varchar(11)?default?'',
    ??`a_hit`?
    int(11)?NOT?NULL?default?'0',
    ??`c_id`?
    int(11)?default?'0',
    ??`a_date`?
    varchar(20)?default?NULL,
    ??
    PRIMARY?KEY??(`a_id`)
    )?

    實(shí)體

    public class articleVO {
    ??? private int a_id;
    ??? private int a_sort;
    ??? private int a_hit;
    ??? private int c_id;
    ??? private String a_title;
    ??? private String a_body;
    ??? private String a_author;
    ??? private String a_date;
    ??? // getter setter


    新建page.java

    package?page.dal;

    public?class?page?{
    ????
    private?int?totalRows;?//總行數(shù)
    ????private?int?pageSize?=?10;?//每頁(yè)顯示的行數(shù)
    ????private?int?currentPage;?//當(dāng)前頁(yè)號(hào)
    ????private?int?totalPages;?//總頁(yè)數(shù)
    ????private?int?startRow;?//當(dāng)前頁(yè)在數(shù)據(jù)庫(kù)中的起始行

    ????
    public?page(int?_totalRows)?{
    ?????totalRows?
    =?_totalRows;
    ?????totalPages
    =totalRows/pageSize;
    ?????
    int?mod=totalRows%pageSize;
    ?????
    if(mod>0){
    ???????totalPages
    ++;
    ?????}
    ?????currentPage?
    =?1;
    ?????startRow?
    =?0;
    ???}

    ???
    public?int?getStartRow()?{
    ?????
    return?startRow;
    ???}

    ???
    public?int?getTotalPages()?{
    ?????
    return?totalPages;
    ???}

    ???
    public?int?getCurrentPage()?{
    ?????
    return?currentPage;
    ???}

    ???
    public?int?getPageSize()?{
    ?????
    return?pageSize;
    ???}

    ???
    public?void?setTotalRows(int?totalRows)?{
    ?????
    this.totalRows?=?totalRows;
    ???}

    ???
    public?void?setStartRow(int?startRow)?{
    ?????
    this.startRow?=?startRow;
    ???}

    ???
    public?void?setTotalPages(int?totalPages)?{
    ?????
    this.totalPages?=?totalPages;
    ???}

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

    ???
    public?void?setPageSize(int?pageSize)?{
    ?????
    this.pageSize?=?pageSize;
    ???}

    ???
    public?int?getTotalRows()?{
    ?????
    return?totalRows;
    ???}

    ???
    public?void?first()?{
    ?????currentPage?
    =?1;
    ?????startRow?
    =?0;
    ???}

    ???
    public?void?previous()?{
    ?????
    if?(currentPage?==?1)?{
    ???????
    return;
    ?????}
    ?????currentPage
    --;
    ?????startRow?
    =?(currentPage?-?1)?*?pageSize;
    ???}

    ???
    public?void?next()?{
    ?????
    if?(currentPage?<?totalPages)?{
    ???????currentPage
    ++;
    ?????}
    ?????startRow?
    =?(currentPage?-?1)?*?pageSize;
    ???}

    ???
    public?void?last()?{
    ?????currentPage?
    =?totalPages;
    ?????startRow?
    =?(currentPage?-?1)?*?pageSize;
    ???}

    ???
    public?void?refresh(int?_currentPage)?{
    ?????currentPage?
    =?_currentPage;
    ?????
    if?(currentPage?>?totalPages)?{
    ???????last();
    ?????}
    ???}

    ?}



    新建 pageHelp.java

    package?page.dal;
    import?javax.servlet.http.*;

    public?class?PagerHelp?{
    ????
    public?static?page?getPager(HttpServletRequest?httpServletRequest,int?totalRows)?{

    ?????
    //定義pager對(duì)象,用于傳到頁(yè)面
    ?????page?pager?=?new?page(totalRows);

    ?????
    //從Request對(duì)象中獲取當(dāng)前頁(yè)號(hào)
    ?????String?currentPage?=?httpServletRequest.getParameter("currentPage");

    ?????
    //如果當(dāng)前頁(yè)號(hào)為空,表示為首次查詢?cè)擁?yè)
    ?????
    //如果不為空,則刷新page對(duì)象,輸入當(dāng)前頁(yè)號(hào)等信息
    ?????if?(currentPage?!=?null)?{
    ???????pager.refresh(Integer.parseInt(currentPage));
    ?????}

    ?????
    //獲取當(dāng)前執(zhí)行的方法,首頁(yè),前一頁(yè),后一頁(yè),尾頁(yè)。
    ?????String?pagerMethod?=?httpServletRequest.getParameter("pageMethod");

    ?????
    if?(pagerMethod?!=?null)?{
    ???????
    if?(pagerMethod.equals("first"))?{
    ?????????pager.first();
    ???????}?
    else?if?(pagerMethod.equals("previous"))?{
    ?????????pager.previous();
    ???????}?
    else?if?(pagerMethod.equals("next"))?{
    ?????????pager.next();
    ???????}?
    else?if?(pagerMethod.equals("last"))?{
    ?????????pager.last();
    ???????}
    ?????}
    ?????
    return?pager;
    ???}

    }



    新建 util.java
    package?page.dal;
    import?net.sf.hibernate.Query;
    import?net.sf.hibernate.cfg.Configuration;
    import?java.util.List;
    import?net.sf.hibernate.HibernateException;
    import?net.sf.hibernate.SessionFactory;
    import?net.sf.hibernate.Session;
    import?java.util.*;
    public?class?util?{
    ????
    public?util()?{
    ????}
    ?????
    private?Session?ss=null;
    ????
    public?Session?getSession()
    ??{
    ??????
    //??Configuration?config=null;
    ??????SessionFactory?sessionFactory;
    ??????
    try?{
    ??????????Configuration?cfg?
    =?new?Configuration();
    ??????????sessionFactory?
    =?cfg.addClass(articleVO.class).
    ???????????????????????????buildSessionFactory();
    ??????????
    //?SessionFactory?sessionFactory=config.buildSessionFactory();
    ??????????ss?=?sessionFactory.openSession();
    ??????????
    return?ss;
    ??????}?
    catch?(HibernateException?ex)?{
    ??????????System.out.print(
    "getsession出錯(cuò)了。。"?+?ex.getMessage());
    ??????????
    return?null;
    ??????}
    ??}

    ??
    public?int?getCount()
    ??{
    ??????String?sql
    ="select?count(*)?from?articleVO"?;
    ??????
    this.getSession();

    ????
    try?{
    ?????
    //?ss.createQuery("select?count(a)as?cont?from?articleVO?a?");
    ??????int?rows=?((Integer)?ss.iterate(sql).next()).intValue();
    ??????ss.flush();
    ??????
    return?rows;

    ????}?
    catch?(HibernateException?ex)?{
    ????????System.out.print(
    "ex::"+ex.getMessage());
    ????????
    return?0;
    ????}


    ??}

    ??
    public?Collection??getList(int?pagesize,int?currow)?throws?HibernateException?{
    ??????Collection?vehicleList?
    =?null;
    ??????
    this.getSession();
    ??????Query?q
    =ss.createQuery("from?articleVO");
    ??????q.setFirstResult(currow);
    ??????q.setMaxResults(pagesize);
    ??????vehicleList
    =q.list();
    ??????ss.flush();
    ??????
    return?vehicleList;
    ??}

    }


    新建 struts? PageAction.java


    package?page.dal;

    import?org.apache.struts.action.ActionMapping;
    import?org.apache.struts.action.ActionForm;
    import?javax.servlet.http.HttpServletRequest;
    import?javax.servlet.http.HttpServletResponse;
    import?org.apache.struts.action.ActionForward;
    import?org.apache.struts.action.Action;
    import?page.dal.*;
    import?java.util.*;
    import?net.sf.hibernate.*;

    public?class?pageAction?extends?Action?{
    ????
    public?ActionForward?execute(ActionMapping?mapping,?ActionForm?form,
    ?????????????????????????????????HttpServletRequest?request,
    ?????????????????????????????????HttpServletResponse?response)?{
    ????????Collection?clInfos?
    =?null;//用于輸出到頁(yè)面的記錄集合
    ????????int?totalRows;//記錄總行數(shù)
    ????????util?dal=new?util();
    ????????totalRows
    =dal.getCount();
    ????????System.out.print(
    "總行數(shù)=="+totalRows);
    ????????page?p
    =PagerHelp.getPager(request,totalRows);
    ????????
    try?{
    ????????????clInfos?
    =?dal.getList(p.getPageSize(),?p.getStartRow());

    ????????}?
    catch?(HibernateException?ex)?{
    ????????????System.out.print(
    "action里的錯(cuò)誤="+ex.getMessage());
    ????????}
    ????????request.setAttribute(
    "page",p);
    ????????request.setAttribute(
    "list",clInfos);
    ????????
    return?mapping.findForward("page");
    ????????
    //pageForm?pageForm?=?(pageForm)?form;
    ??????
    //??throw?new?java.lang.UnsupportedOperationException(
    ??????????????
    //??"Method?$execute()?not?yet?implemented.");
    ????}
    }


    前臺(tái)頁(yè)面

    <%@?taglib?uri="/WEB-INF/struts-tiles.tld"?prefix="tiles"?%>
    <%@?taglib?uri="/WEB-INF/struts-nested.tld"?prefix="nested"?%>
    <%@?taglib?uri="/WEB-INF/struts-logic.tld"?prefix="logic"?%>
    <%@?taglib?uri="/WEB-INF/struts-bean.tld"?prefix="bean"?%>
    <%@?taglib?uri="/WEB-INF/struts-html.tld"?prefix="html"?%>
    <%@?page?contentType="text/html;?charset=GBK"?%>
    <html:html>
    <head>
    <title>
    page
    </title>
    </head>
    <body>
    <table?align="center"?border="2">
    <tr>
    <th>a_title</th>
    <th>a_body</th>
    <th>a_a_date</th>
    <th>a_author</th>
    </tr>

    <logic:iterate?id="listd"?name="list">
    <tr>
    <td>
    <bean:write?name="listd"?property="a_title"/>
    </td>
    <td>
    <bean:write?name="listd"?property="a_author"/>
    </td>
    <td>
    <bean:write?name="listd"?property="a_date"/>
    </td>
    <td>
    <bean:write?name="listd"?property="a_date"/>
    </td>
    </tr>
    </logic:iterate>

    </table>

    <bean:write?name="page"?property="currentPage"/>頁(yè)
    <bean:write?name="page"?property="totalPages"?/>頁(yè)
    <html:link?action="/pageAction.do?pageMethod=first"
    paramName
    ="page"?paramProperty="currentPage"?paramId="currentPage">首頁(yè)</html:link>
    ???
    <html:link?action="/pageAction.do?pageMethod=previous"
    paramName
    ="page"?paramProperty="currentPage"?paramId="currentPage">上一頁(yè)</html:link>
    ???
    <html:link?action="/pageAction.do?pageMethod=next"
    paramName
    ="page"?paramProperty="currentPage"?paramId="currentPage">下一頁(yè)</html:link>

    ???
    <html:link?action="/pageAction.do?pageMethod=last"
    paramName
    ="page"?paramProperty="currentPage"?paramId="currentPage">尾頁(yè)</html:link>
    </body>
    </html:html>



    啟動(dòng)瀏覽 pageAction.do? 運(yùn)行OK。



    ****************************************************************************************


    配置文件


    <?xml?version="1.0"?encoding="UTF-8"?>

    <!DOCTYPE?hibernate-mapping?PUBLIC
    ????"-//Hibernate/Hibernate?Mapping?DTD?2.0//EN"
    ????"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"
    >
    <hibernate-mapping>

    ????
    <class?name="page.dal.articleVO"?table="t_article"?>


    ????
    <id?name="a_id"?column="a_id"?unsaved-value="0"?>
    ??????
    <generator?class="native"/>
    ?
    </id>
    ?????
    <property?name="c_id"????column="c_id"/>
    ?????
    <property?name="a_title"?column="a_title"/>
    ?????
    <property?name="a_sort"??column="a_sort"/>
    ?????
    <property?name="a_date"??column="a_date"/>
    ?????
    <property?name="a_body"??column="a_body"/>
    ?????
    <property?name="a_hit"???column="a_hit"/>
    ?????
    <property?name="a_author"?column="a_author"/>
    ???
    ????
    ??
    </class>

    </hibernate-mapping>

    hibernate.dialect?net.sf.hibernate.dialect.MySQLDialect
    hibernate.connection.driver_class?org.gjt.mm.mysql.Driver
    hibernate.connection.url?jdbc:mysql://localhost:
    3306/wjcms
    hibernate.connection.username?root
    hibernate.connection.password?
    hibernate.connection.pool_size?
    1
    hibernate.proxool.pool_alias?pool1
    hibernate.show_sql?true
    hibernate.max_fetch_depth?
    1
    hibernate.cache.use_query_cache?true
    主站蜘蛛池模板: 日本免费人成网ww555在线| 亚洲av无码兔费综合| 亚洲一级在线观看| 亚洲熟妇自偷自拍另欧美| 在线亚洲v日韩v| 精品免费久久久久国产一区 | 亚洲美女大bbbbbbbbb| 亚洲国产成人综合| 亚洲AV成人片无码网站| 精品人妻系列无码人妻免费视频| 日韩精品无码一区二区三区免费| 黄色片在线免费观看| 国产免费拔擦拔擦8x| 亚洲人成中文字幕在线观看| 亚洲伊人久久大香线蕉苏妲己| 国产精品亚洲精品| 亚洲免费视频一区二区三区| 99久久精品免费精品国产| 天天天欲色欲色WWW免费| 中文字幕亚洲电影| 亚洲国产精品成人综合色在线婷婷| 亚洲AV无码一区二区三区网址| 成人片黄网站色大片免费观看cn| 亚洲最大免费视频网| 免费吃奶摸下激烈视频| 91亚洲国产成人久久精品网站| 精品久久久久久久久亚洲偷窥女厕| 免费无码又爽又刺激一高潮| 在线观看特色大片免费视频| 337p日本欧洲亚洲大胆裸体艺术| 亚洲人成免费网站| 国产成人无码精品久久久免费| 在线视频免费观看爽爽爽| 亚洲精品网站在线观看不卡无广告| 91亚洲国产成人精品下载| 男女男精品网站免费观看 | 国产午夜不卡AV免费| 暖暖免费高清日本中文| 亚洲国产天堂久久综合网站| 精品国产日韩亚洲一区91 | 久久中文字幕免费视频|