我用Struts+Hibernate做了一个新闻发布系统,其中新闻上就有一个点击率,可是每次
刷新过后次数都刷信不过来!
请各位高手指点!!!

解决方案 »

  1.   

    就是点击新闻的时候啊,那个点击率刷新不过来!
    新闻读取用:
    public List findAll() {
    log.debug("finding all Zb instances");
    try {
    String queryString = "FROM Zb order by id desc";
    Query queryObject = getSession().createQuery(queryString);
    return queryObject.list();
    } catch (RuntimeException re) {
    log.error("find all failed", re);
    throw re;
    }
    }
    新闻点击率的更新用:
    public void updatecount(int id)
    {
    String hql="update Zb as a set a.count=a.count+1 where a.id=?";
    Query query=getSession().createQuery(hql);
    query.setInteger(0,id);
    query.executeUpdate();
    getSession().beginTransaction().commit();
    }
      

  2.   

    没咋用过hibernate,你这问题似乎是读取的时候使用了缓存 在刷新前清空缓存区
      

  3.   

    数据库里已经完成了+1操作!
    Action中通过request.setAttribute("list",list)将读出的数据保存到request中
    数据显示代码:
    <logic:present name="list" scope="request">
    <td width="117" height="35"><span style="font-weight: bold">日期</span>:${list.date}</td>
    <td width="122"><span style="font-weight: bold">作者</span>:${list.user1}</td>
    <td width="389"><span style="font-weight: bold">点击:${list.count}</span></td>
    <td  align="center" height="34" colspan="5"><span style="font-size: 16px">${list.title}</span></td>
    </logic:present>
      

  4.   

    request.setAttribute("list",list)用session.setAttribute("list",list)或者application.setAttribute("list",list)
      

  5.   

    你是怎么在Action中通过request.setAttribute("list",list)将读出的数据保存到request中的?list是什么? 
      

  6.   

    list就是通过方法获得的:
    public List findAll() { 
        log.debug("finding all Zb instances"); 
        try { 
            String queryString = "FROM Zb order by id desc"; 
            Query queryObject = getSession().createQuery(queryString); 
            return queryObject.list(); 
        } catch (RuntimeException re) { 
            log.error("find all failed", re); 
            throw re; 
        } 

      

  7.   

    这样的话不能直接用list.count来取得次数,要取出list里的第一条数据(应该是个对象,比如是a),然后用a.count取次数.
      

  8.   

    用<logic:present name="list" scope="request"> 
    日期:${list.date}
    作者:${list.user1} 
    点击:${list.count} 
    标题:${list.title}
    </logic:present>
    这样读取的其他数据没问题的,就是读出的数据好像还是上次的数据!!!!
      

  9.   

    这个是hibernate的缓存问题,
    你在session.creqtequery("")时候要清空缓存区