锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品最新地址,国产高清自产拍av在线,国产精品久久久久久久久图文区 http://www.aygfsteel.com/Crying/category/26081.html涓轟簡鑷繁zh-cnSat, 22 Sep 2007 13:12:58 GMTSat, 22 Sep 2007 13:12:58 GMT60hibernate鍒嗛〉1http://www.aygfsteel.com/Crying/articles/147398.htmlCryingCryingSat, 22 Sep 2007 05:53:00 GMThttp://www.aygfsteel.com/Crying/articles/147398.htmlhttp://www.aygfsteel.com/Crying/comments/147398.htmlhttp://www.aygfsteel.com/Crying/articles/147398.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/147398.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/147398.html  鐩殑錛?/span>

瀛︿範浣跨敤struts+hibernate瀹炵幇涓涓氱敤鐨勫垎欏電▼搴忋?/span>

鍐呭錛?/span>

    鍒嗛〉紼嬪簭鏄綉欏佃璁$粡甯擱渶瑕佸疄鐜扮殑鍩烘湰鍔熻兘銆備絾鏈夌殑鍒嗛〉紼嬪簭鐩存帴宓屽湪jsp欏甸潰涓婏紝涓嶄粎宸ヤ綔閲忚緝澶э紝浠g爜涔熼毦浠ラ噸鐢ㄣ傛湰嬈¤瘯楠屽皢浣跨敤struts+hibernate鏉ュ疄鐜伴氱敤鐨勫垎欏電▼搴忋備笉鍚屽姛鑳界殑浠g爜灝介噺鍒嗙錛屼互婊¤凍閫氱敤鎬ц姹傘?/span>

    棣栧厛闇瑕佸緩绔嬩竴涓〃錛屽涓婸roduct,鍚勫瓧孌佃璁″涓?鍙嚜鐢辨洿鏀?錛?/span>

    ID int primary key,

    Typeid varchar(20),

Name   varchar(50),

Price    varchar(20),

Memo   varchar(100).

姝ラ錛?/span>

寤虹珛web宸ョ▼錛屽悕瀛椾負”Fenye”.

2 娣誨姞hibernate錛岀敓鎴?/span>Product琛ㄧ殑.hbm.xml鍜?/span>pojo綾匯傝繖涓緢綆鍗曪紝涓嶅啀璧樿堪銆?/span>

3 鎺ョ潃鍐欐暟鎹闂眰錛屾垜浠皢鍏跺垎涓?/span>Dao鍜?/span>ProDao涓や釜綾匯傚叾涓?/span>Dao鏄釜鍏叡鐨勫熀綾伙紱ProDao緇ф壙瀹冿紝騫朵笌action閫氫俊鍙栧緱鍙傛暟銆傝繖鏍瘋璁$殑濂藉鏄細濡傛灉闇瑕佸User榪欎釜琛ㄨ繘琛屽垎欏墊樉紺猴紝鍙渶娣誨姞涓涓?/span>UserDao綾伙紝騫惰瀹冪戶鎵?/span>Dao綾匯?/span>

Dao綾葷殑浠g爜濡備笅錛屽彲浠ユ牴鎹渶瑕佹坊鍔狅細澶存枃浠惰嚜宸卞鍏ャ?/span>

public class Dao {

        private Session session=null;

        public Dao() {

           }

          

           public Session getSession()

        {

             session = HibernateSessionFactory.getSession();

               return session;       

        }

          public int getCount(String pojo)

        {

             String sql="select count(*) from "+pojo ;

             this.getSession();

           try {

           Query q = getSession().createQuery(sql);

             List cc = q.list();

             Integer rows = (Integer) cc.get(0);

           return rows.intValue();

           } catch (HibernateException ex) {

               System.out.print("ex::"+ex.getMessage());

               return 0;

           }

        }

        public List getlist(Query query, String pojo,int pagesize,int currow) throws HibernateException

       {

             List list = null;

             this.getSession();

            query.setFirstResult(currow);

             query.setMaxResults(pagesize);

             list=query.list();

             //session.flush();

             if(session!=null)

                     session.close();     

             return list;

        }

        public List getlist(Query query,int pagesize,int currow)

              {                  

                      String[] str = query.getQueryString().split("from");       

                      String[] table =str[1].trim().split(" ");        

                      System.out.println("table:"+table[0]);

                      return getlist(query,table[0],pagesize,currow);         

              }

}

ProDao綾葷殑浠g爜濡備笅錛?/span>

public class PinfoDao extends Dao{

       private Session session;

       public PinfoDao() {

              super();

    }

       public List list(int pagesize,int currow)

       {

             

              Query query =getSession().createQuery("from PInfo");

              List li=getlist(query, pagesize, currow);

              return li;

             

       }

        public Session getSession()

        {

             // Configuration config=null;

          

             session = HibernateSessionFactory.getSession();

               return session; 

        }

       public int getCount()

       {

              String sql="select count(*) from PInfo";

              Query q = getSession().createQuery(sql);

              List cc = q.list();

              Integer a = (Integer) cc.get(0);    

              System.out.println("count:"+a.intValue());

              return a.intValue();

       }    

}

4         涓嬮潰鍐欓〉闈㈡帶鍒剁▼搴忥紝鍚屾牱灝嗕唬鐮佸垎紱諱負涓や釜綾?/span>Page綾誨拰Pagehelp綾匯?/span>

Page綾誨鐞嗛〉闈㈢浉鍏崇殑涓浜涜緗紝濡備竴欏墊樉紺哄灝戞潯璁板綍錛岃綆楀叡鏈夊灝戦〉錛屽叡鏈夊灝戣褰曪紝褰撳墠欏電爜絳夈?/span>

PageHelp綾繪帴鏀?/span>jsp欏甸潰浼犳潵鐨勫弬鏁幫紝騫惰皟鐢?/span>Page綾誨鐞嗐?/span>

Page綾諱唬鐮侊細

public class Page {

        private int totalRows; //鎬昏鏁?/span>

           private int pageSize = 3; //姣忛〉鏄劇ず鐨勮鏁?/span>

           private int currentPage; //褰撳墠欏靛彿

           private int totalPages; //鎬婚〉鏁?/span>

           private int startRow; //褰撳墠欏靛湪鏁版嵁搴撲腑鐨勮搗濮嬭

           public Page(int totalRows1) {

            totalRows = totalRows1;

            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綾諱唬鐮佸涓嬶細

public class Pagehelp {

        public static Page getPager(HttpServletRequest httpServletRequest,int totalRows) {

      //瀹氫箟pager瀵硅薄錛岀敤浜庝紶鍒伴〉闈?/span>

      Page pager = new Page(totalRows);

      //浠?/span>Request瀵硅薄涓幏鍙栧綋鍓嶉〉鍙?/span>

      String currentPage = httpServletRequest.getParameter("currentPage");

      //濡傛灉褰撳墠欏靛彿涓虹┖錛岃〃紺轟負棣栨鏌ヨ璇ラ〉

      //濡傛灉涓嶄負絀猴紝鍒欏埛鏂?/span>page瀵硅薄錛岃緭鍏ュ綋鍓嶉〉鍙風瓑淇℃伅

      if (currentPage != null) {

        pager.refresh(Integer.parseInt(currentPage));

      }

      //鑾峰彇褰撳墠鎵ц鐨勬柟娉曪紝棣栭〉錛屽墠涓欏碉紝鍚庝竴欏碉紝灝鵑〉銆?/span>

      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;

    }

}

5         涓鍒囧噯澶囧伐浣滅粨鏉熷悗錛屼笅闈㈠啓action鏉ヨ皟鐢ㄨ繖浜涚被銆?/span>

List list = null;//鐢ㄤ簬杈撳嚭鍒伴〉闈㈢殑璁板綍闆嗗悎

               int totalRows;//璁板綍鎬昏鏁?/span>

               PinfoDao dao=new PinfoDao();

               totalRows=dao.getCount();

               System.out.print("鎬昏鏁?/span>=="+totalRows);

               Page page=Pagehelp.getPager(request,totalRows);

               try {

                      list= dao.list(page.getPageSize(), page.getStartRow());

               } catch (HibernateException ex) {

                   System.out.print("action閲岀殑閿欒="+ex.getMessage());

               }

               request.setAttribute("page",page);

               request.setAttribute("list",list);

               return mapping.findForward("list");

6         鏈鍚庢槸鏄劇ず欏甸潰plist銆傚湪struts-config.xml鏂囦歡涓坊鍔?/span>forward璇彞錛?/span><forward name="list" path="/plist.jsp"></forward>銆?/span>

plist.jsp欏甸潰閮ㄥ垎浠g爜濡備笅錛?/span>

<table align="center" border="1">

   <tr>

   <td>浜у搧綾誨埆</td>

   <td>浜у搧鍚嶇О</td>

   <td>浜у搧浠鋒牸</td>

   <td>浜у搧澶囨敞</td>

   </tr>

<!鈥?/span>涓嬮潰鎵撳嵃list涓殑鍚勫睘鎬?/span>-->

       <tr >

   <td colspan="4">

絎?/span><bean:write name="page" property="currentPage"/>欏?/span>

鍏?/span><bean:write name="page" property="totalPages" />欏?/span>

<html:link action="/page.do?pageMethod=first"

paramName="page" paramProperty="currentPage"

paramId="currentPage">棣栭〉</html:link>

   <html:link action="/page.do?pageMethod=previous"

paramName="page" paramProperty="currentPage"

paramId="currentPage">涓婁竴欏?/span></html:link>

   <html:link action="/page.do?pageMethod=next"

paramName="page" paramProperty="currentPage"

paramId="currentPage">涓嬩竴欏?/span></html:link>

   <html:link action="/page.do?pageMethod=last"

paramName="page" paramProperty="currentPage"

paramId="currentPage">灝鵑〉</html:link>

</td>

</tr>        

</table>

7 嫻嬭瘯錛?/span>

鎸夌収涓婅堪姝ラ瀹屾垚鍚庯紝鍦ㄦ祻瑙堝櫒涓緭鍏?/span>http://localhost:8080/Fenye/page.do鏌ョ湅欏甸潰銆?/span>



Crying 2007-09-22 13:53 鍙戣〃璇勮
]]>
jsp鍒嗛〉http://www.aygfsteel.com/Crying/articles/147397.htmlCryingCryingSat, 22 Sep 2007 05:51:00 GMThttp://www.aygfsteel.com/Crying/articles/147397.htmlhttp://www.aygfsteel.com/Crying/comments/147397.htmlhttp://www.aygfsteel.com/Crying/articles/147397.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/147397.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/147397.html<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*,javax.sql.*,javax.naming.*" %>

<html>
 <head>
  <title>緗戜笂涔﹀簵鐣欒█鏉?lt;/title>
 </head>
 <body>
  <a href="say.html">鎴戣鐣欒█</a><br>
  <%
   Context ctx=new InitialContext();
            DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/bookstore");
            Connection conn=ds.getConnection();
           
            //鍒涘緩鍙粴鍔ㄧ殑緇撴灉闆嗐?br />    Statement stmt=conn.createStatement(
    ResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_READ_ONLY);
   ResultSet rs=stmt.executeQuery("select * from guestbook order by gst_time desc");
   
   //縐誨姩娓告爣鍒扮粨鏋滈泦鐨勬渶鍚庝竴琛屻?br />    rs.last();
   
   //寰楀埌褰撳墠琛岀殑琛屾暟錛屼篃灝卞緱鍒頒簡鏁版嵁搴撲腑鐣欒█鐨勬繪暟銆?br />    int rowCount=rs.getRow();
   if(rowCount==0)
   {
    out.println("褰撳墠娌℃湁浠諱綍鐣欒█!");
    return;
   }
   
   String strCurPage=request.getParameter("page");
   
   //琛ㄧず褰撳墠鐨勯〉鏁般?br />    int curPage;
   
   if(strCurPage==null)
    curPage=1;
   else
    curPage=Integer.parseInt(strCurPage);
   
   //瀹氫箟姣忛〉鏄劇ず鐨勭暀璦鏁般?br />    int countPerPage=5;
   
   //璁$畻鏄劇ず鎵鏈夌暀璦闇瑕佺殑鎬婚〉鏁般?br />    int pageCount=(rowCount+countPerPage-1)/countPerPage;
   
   //縐誨姩娓告爣鍒扮粨鏋滈泦涓寚瀹氱殑琛屻傚鏋滄樉紺虹殑鏄涓欏碉紝curPage=1錛?br />    //娓告爣縐誨姩鍒扮1琛屻?br />    rs.absolute((curPage-1)*countPerPage+1);
   
      //濡傛灉鏄1欏碉紝鍒欐樉紺轟笉甯﹂摼鎺ョ殑鏂囧瓧錛屽鏋滀笉鏄1欏碉紝
      //鍒欑粰鐢ㄦ埛鎻愪緵璺寵漿鍒扮涓欏靛拰涓婁竴欏電殑閾炬帴銆?br />    if(curPage==1)
   { 
  %>
          絎竴欏?amp;nbsp;&nbsp;&nbsp;&nbsp;
          涓婁竴欏?amp;nbsp;&nbsp;&nbsp;&nbsp;
  <%
   }
   else
   {
  %>
          <a href="index.jsp?page=<%=1%>">絎竴欏?lt;/a>
          &nbsp;&nbsp;&nbsp;&nbsp;
          <a href="index.jsp?page=<%=curPage-1%>">涓婁竴欏?lt;/a>
          &nbsp;&nbsp;&nbsp;&nbsp;
  <%
   }
   //濡傛灉褰撳墠欏墊槸鏈鍚庝竴欏碉紝鍒欐樉紺轟笉甯﹂摼鎺ョ殑鏂囧瓧錛屽鏋滀笉鏄渶鍚庝竴欏碉紝
   //鍒欑粰鐢ㄦ埛鎻愪緵璺寵漿鍒版渶鍚庝竴欏靛拰涓嬩竴欏電殑閾炬帴銆?br />    if(curPage==pageCount)
   {
   
  %>
          涓嬩竴欏?amp;nbsp;&nbsp;&nbsp;&nbsp;
          鏈鍚庨〉&nbsp;&nbsp;&nbsp;&nbsp;
  <%
   }
   else
   {
  %>
          <a href="index.jsp?page=<%=curPage+1%>">涓嬩竴欏?lt;/a>
          &nbsp;&nbsp;&nbsp;&nbsp;
          <a href="index.jsp?page=<%=pageCount%>">鏈鍚庨〉</a>
          &nbsp;&nbsp;&nbsp;&nbsp;
  <%
   }
   
   int i=0;
   
   //浠ュ驚鐜殑鏂瑰紡鍙栧嚭姣忛〉瑕佹樉紺虹殑鏁版嵁錛屽洜涓哄湪鍓嶉潰閽堝瑕佹樉紺虹殑欏墊暟錛?br />    //璋冪敤浜唕s.absolute((curPage-1)*countPerPage+1);
   //鎵浠ユ槸浠庢父鏍囨墍鍦ㄧ殑浣嶇疆鍙栧嚭褰撳墠欏佃鏄劇ず鐨勬暟鎹?br />    while(i<countPerPage && !rs.isAfterLast())
   {
    out.println("<hr color=\"blue\" size=\"2\"><br>");
    out.println("鐢ㄦ埛鍚嶏細"+rs.getString("gst_user"));
    out.println("&nbsp;&nbsp;");
    
    Timestamp ts=rs.getTimestamp("gst_time");
    long lms=ts.getTime();
    Date date=new Date(lms);
    Time time=new Time(lms);
    
    out.println("鐣欒█鏃墮棿錛?+date+" "+time);
    
    out.println("&nbsp;&nbsp;");
    out.println("鐢ㄦ埛IP錛?+rs.getString("gst_ip")+"<br>");
    out.println("涓婚錛?+rs.getString("gst_title")+"<br>");
    out.println("鍐呭錛?+rs.getString("gst_content"));
    i++;
    rs.next(); 
   }
   rs.close();
   stmt.close();
   conn.close();
  %>
 </body>
</html>



Crying 2007-09-22 13:51 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 东莞市| 交口县| 胶州市| 佛山市| 若羌县| 嘉荫县| 定襄县| 襄汾县| 津南区| 米林县| 丁青县| 湖南省| 天柱县| 富锦市| 丹东市| 黎平县| 双峰县| 定州市| 丰都县| 离岛区| 潍坊市| 永仁县| 麦盖提县| 岳阳市| 玛纳斯县| 肇州县| 望城县| 循化| 侯马市| 长垣县| 灵璧县| 随州市| 滨州市| 大足县| 吴堡县| 莱州市| 榆树市| 连南| 靖西县| 郸城县| 三明市|