谢谢大虾们!

解决方案 »

  1.   

    你要计算的,我给你个类似的例子,是我以前写的,也是struts   +   hibernate 存放信息的实体类 
    package   com.entitys; import   java.io.Serializable; public   class   Product   implements   Serializable{ 
    private   String   productId; 
    private   String   productName; 
    private   int   num; 
    private   double   price; 
    private   String   factoryName; 
    private   String   tel; public   Product(){} public   Product(String   productId,String   productName,int   num,double   price,String   factoryName,String   tel){ 
    this.productId   =   productId; 
    this.productName   =   productName; 
    this.num   =   num; 
    this.price   =   price; 
    this.factoryName   =   factoryName; 
    this.tel   =   tel; 
    } public   String   getFactoryName()   { 
    return   factoryName; 

    public   void   setFactoryName(String   factoryName)   { 
    this.factoryName   =   factoryName; 

    public   int   getNum()   { 
    return   num; 

    public   void   setNum(int   num)   { 
    this.num   =   num; 

    public   double   getPrice()   { 
    return   price; 

    public   void   setPrice(double   price)   { 
    this.price   =   price; 

    public   String   getProductId()   { 
    return   productId; 

    public   void   setProductId(String   productId)   { 
    this.productId   =   productId; 

    public   String   getProductName()   { 
    return   productName; 

    public   void   setProductName(String   productName)   { 
    this.productName   =   productName; 

    public   String   getTel()   { 
    return   tel; 

    public   void   setTel(String   tel)   { 
    this.tel   =   tel; 

      

  2.   

    访问数据库的类 
    package   com.dbaccess; import   java.util.Collection; 
    import   java.util.List; import   org.hibernate.Query; 
    import   org.hibernate.Session; import   com.Icommand.IProduct; 
    import   com.hibernateFactory.HibernateSessionFactory; public   class   AccessProduct   implements   IProduct   { 
    private   int   currentPage;//当前页面数 
    private   int   pageCount;//总页面数 public   Collection   getAllProduct(int   page)   { 
    Session   session   =   getSession(); 
    synchronized   (session)   { 
    try{ 
    this.currentPage   =   page; String   hql   =   "from   Product "; 
    Query   query   =   session.createQuery(hql); int   rows=10;   //   每页显示10行 List   list   =   query.list(); int   count   =   list.size();   //   记录总数 this.pageCount=(count+rows-1)/rows;   //   根据你的纪录总数,显示行数,来计算分多少页 /*如果当前页面数小于1,则让当前页面数等于1*/ 
    if(this.currentPage <1) 

    this.currentPage=1; 

    /*如果当前页面数大于总页数,则让当前页面数等于总页数*/ 
    if(this.currentPage> this.pageCount) 

    this.currentPage=this.pageCount; 
    } List   newList; 
    if((((this.currentPage-1)*rows)+rows)> count) 

    newList   =   list.subList((this.currentPage-1)*rows,   count); 

    else 

    newList   =   list.subList((this.currentPage-1)*rows,   ((this.currentPage-1)*rows)+rows); 
    } return   newList; 

    catch(Exception   e){ 
    e.printStackTrace(); 
    return   null; 


    } public   int   getCurrentPage()   { 
    return   currentPage; 
    } public   int   getPageCount()   { 
    return   pageCount; 
    } private   Session   getSession(){ 
    Session   session   =   null; 
    try 

    session   =   HibernateSessionFactory.getSession(); 

    catch(Exception   e){ 
    e.printStackTrace(); 

    return   session; 


    数据访问对象工厂类   
    package   com.dbfactory; import   com.Icommand.IProduct; 
    import   com.dbaccess.AccessProduct; public   class   ProductFactory   { private   ProductFactory(){} public   static   IProduct   getInstance(){ 
    return   new   AccessProduct(); 


    业务逻辑类 
    package   com.logic; import   java.util.Collection; import   com.Icommand.IProduct; 
    import   com.dbfactory.ProductFactory; public   class   ProductLogic   { private   IProduct   proDB   =   ProductFactory.getInstance(); 
    public   Collection   getAllProduct(int   page){ 
    return   proDB.getAllProduct(page); 
    } public   int   getCurrentPage(){ 
    return   proDB.getCurrentPage(); 
    } public   int   getPageCount(){ 
    return   proDB.getPageCount(); 


    function liuyanjia(pageNum){
    //curPage+=pageNum;
    var req = new XMLHttpRequest();
    //alert(req);
    var aa= [];
            if (req) 
            {  
              req.onreadystatechange = function() 
              {    
                if (req.readyState == 4 && (req.status == 200 || req.status == 304)) 
                {    
                  //处理返回结果  
                  //var rst = req.responseText;
                  //alert("asdf.......");
                  var items = req.responseXML.getElementsByTagName("item");              
                  for (var i=0; i < items.length; i++)
      {//alert("ss");
    var username = req.responseXML.getElementsByTagName("username")[i].firstChild.nodeValue;
    var liuyan = req.responseXML.getElementsByTagName("liuyan")[i].firstChild.nodeValue;
    var time1 = req.responseXML.getElementsByTagName("time1")[i].firstChild.nodeValue;
    var huifu = req.responseXML.getElementsByTagName("huifu")[i].firstChild.nodeValue;
    //alert(username); 
    aa[i]=[];
    aa[i][0]=username;
    aa[i][1]=liuyan;
    aa[i][2]=time1;
    aa[i][3]=huifu;
    //alert(id);
      }
                  var id1 = jQuery("#id1");
                  var id3 = jQuery("#id3"); 
                  var id4 = jQuery("#id4"); 
                  var id5 = jQuery("#id5"); 
                  var id7 = jQuery("#id7"); 
                  var id8 = jQuery("#id8"); 
                  //alert(aa[0][3]);
                  if(aa[0][3]!="null"&&aa[1][3]!="null"){ 
                   $('.righ_downtext3').show();
                   $('.righ_downtext33').show();
        id1.html(aa[0][0]+" | "+aa[0][2]);  
        id3.html(aa[0][1]);
            id4.html(aa[0][3]);
        id5.html(aa[1][0]+" | "+aa[1][2]);
        id7.html(aa[1][1]);
        id8.html(aa[1][3]);
                  }
                  else if(aa[0][3]=="null"&&aa[1][3]=="null"){
       $('.righ_downtext3').hide();
       $('.righ_downtext33').hide();
        id1.html(aa[0][0]+" | "+aa[0][2]);  
        id3.html(aa[0][1]+"<a href='javascript:changeSta1();'>回复</a>");       
        id5.html(aa[1][0]+" | "+aa[1][2]);
        id7.html(aa[1][1]+"<a href='javascript:changeSta2();'>回复</a>");
      }
                  else if(aa[0][3]=="null"){
       $('.righ_downtext3').hide();
        $('.righ_downtext33').show();
        id1.html(aa[0][0]+" | "+aa[0][2]);  
        id3.html(aa[0][1]+"<a href='javascript:changeSta2();'>回复</a>");
        id5.html(aa[1][0]+" | "+aa[1][2]);
        id7.html(aa[1][1]);
        id8.html(aa[1][3]);  
      }
                  else if(aa[1][3]=="null"){
       $('.righ_downtext33').hide();
        $('.righ_downtext3').show();
        id1.html(aa[0][0]+" | "+aa[0][2]);  
        id3.html(aa[0][1]);
            id4.html(aa[0][3]);
        id5.html(aa[1][0]+" | "+aa[1][2]);
        id7.html(aa[1][1]+"<a href='javascript:changeSta2();'>回复</a>");  
      }   
                }
              }            
              req.open('GET', 'OpenLiuYan.do?pageNums='+pageNum);  
             //window.open('OpenLiuYan.do?pageNums='+pageNum);
              req.send(null);
            }
    }
    function liuyanjian(pageNum){
    //curPage+=pageNum;
    var req = new XMLHttpRequest();
    //alert(req);
    var aa= [];
            if (req) 
            {  
              req.onreadystatechange = function() 
              {    
                if (req.readyState == 4 && (req.status == 200 || req.status == 304)) 
                {    
                  //处理返回结果  
                  //var rst = req.responseText;
                  //alert("asdf.......");
                  var items = req.responseXML.getElementsByTagName("item");              
                  for (var i=0; i < items.length; i++)
      {//alert("ss");
    var username = req.responseXML.getElementsByTagName("username")[i].firstChild.nodeValue;
    var liuyan = req.responseXML.getElementsByTagName("liuyan")[i].firstChild.nodeValue;
    var time1 = req.responseXML.getElementsByTagName("time1")[i].firstChild.nodeValue;
    var huifu = req.responseXML.getElementsByTagName("huifu")[i].firstChild.nodeValue;
    //alert(username); 
    aa[i]=[];
    aa[i][0]=username;
    aa[i][1]=liuyan;
    aa[i][2]=time1;
    aa[i][3]=huifu;
    //alert(id);
      }
                  var id1 = jQuery("#id1");
                  var id3 = jQuery("#id3"); 
                  var id4 = jQuery("#id4"); 
                  var id5 = jQuery("#id5"); 
                  var id7 = jQuery("#id7"); 
                  var id8 = jQuery("#id8"); 
                  //alert(aa[0][3]);
                  if(aa[0][3]!="null"&&aa[1][3]!="null"){ 
                   $('.righ_downtext3').show();
                   $('.righ_downtext33').show();
        id1.html(aa[0][0]+" | "+aa[0][2]);  
        id3.html(aa[0][1]);
            id4.html(aa[0][3]);
        id5.html(aa[1][0]+" | "+aa[1][2]);
        id7.html(aa[1][1]);
        id8.html(aa[1][3]);
                  }
                  else if(aa[0][3]=="null"&&aa[1][3]=="null"){
       $('.righ_downtext3').hide();
       $('.righ_downtext33').hide();
        id1.html(aa[0][0]+" | "+aa[0][2]);  
        id3.html(aa[0][1]+"<a href='javascript:changeSta1();'>回复</a>");       
        id5.html(aa[1][0]+" | "+aa[1][2]);
        id7.html(aa[1][1]+"<a href='javascript:changeSta2();'>回复</a>");
      }
                  else if(aa[0][3]=="null"){
       $('.righ_downtext3').hide();
        $('.righ_downtext33').show();
        id1.html(aa[0][0]+" | "+aa[0][2]);  
        id3.html(aa[0][1]+"<a href='javascript:changeSta2();'>回复</a>");
        id5.html(aa[1][0]+" | "+aa[1][2]);
        id7.html(aa[1][1]);
        id8.html(aa[1][3]);  
      }
                  else if(aa[1][3]=="null"){
       $('.righ_downtext33').hide();
        $('.righ_downtext3').show();
        id1.html(aa[0][0]+" | "+aa[0][2]);  
        id3.html(aa[0][1]);
            id4.html(aa[0][3]);
        id5.html(aa[1][0]+" | "+aa[1][2]);
        id7.html(aa[1][1]+"<a href='javascript:changeSta2();'>回复</a>");  
      }   
                }
              }            
              req.open('GET', 'OpenLiuYan.do?pageNums='+pageNum);  
             //window.open('OpenLiuYan.do?pageNums='+pageNum);
              req.send(null);
            }
    }http://www.jspcn.net/htmlnews/11049397860001683.htmlhttp://jiaxianglai2.blog.163.com/blog/static/119072118200910200501593/   分页http://www.jb51.net/article/2522.htmhttp://www.jb51.net/article/2580.htm