zhangqiyi
zhangqiyi
2012-11-29 17:35
浏览 233
已采纳

spring+hibernate+struts1分页问题

我在使用Oracle9iDialect进行分页时发现在页面超过20页有时候出现每一页显示和前一页内容一样,后来发现数据库用的是11g而hibernate方言用的是Oracle9iDialect,把Oracle9iDialect换成OracleDialect就没有问题了,求解

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • jinnianshilongnian
    jinnianshilongnian 2012-11-29 18:32
    已采纳

    分页sql是通过dialect生成的

    OracleDialect
    [code="java"] public String getLimitString(String sql, boolean hasOffset) {

        sql = sql.trim();
        boolean isForUpdate = false;
        if ( sql.toLowerCase().endsWith(" for update") ) {
            sql = sql.substring( 0, sql.length()-11 );
            isForUpdate = true;
        }
    
        StringBuffer pagingSelect = new StringBuffer( sql.length()+100 );
        if (hasOffset) {
            pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
        }
        else {
            pagingSelect.append("select * from ( ");
        }
        pagingSelect.append(sql);
        if (hasOffset) {
            pagingSelect.append(" ) row_ ) where rownum_ <= ? and rownum_ > ?");
        }
        else {
            pagingSelect.append(" ) where rownum <= ?");
        }
    
        if ( isForUpdate ) {
            pagingSelect.append( " for update" );
        }
    
        return pagingSelect.toString();
    }[/code]
    

    Oracle9iDialect
    [code="java"] public String getLimitString(String sql, boolean hasOffset) {

        sql = sql.trim();
        boolean isForUpdate = false;
        if ( sql.toLowerCase().endsWith(" for update") ) {
            sql = sql.substring( 0, sql.length()-11 );
            isForUpdate = true;
        }
    
        StringBuffer pagingSelect = new StringBuffer( sql.length()+100 );
        if (hasOffset) {
            pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
        }
        else {
            pagingSelect.append("select * from ( ");
        }
        pagingSelect.append(sql);
        if (hasOffset) {
            pagingSelect.append(" ) row_ where rownum <= ?) where rownum_ > ?");
        }
        else {
            pagingSelect.append(" ) where rownum <= ?");
        }
    
        if ( isForUpdate ) {
            pagingSelect.append( " for update" );
        }
    
        return pagingSelect.toString();
    }
    

    [/code]

    唯一不同点:

        if (hasOffset) {
            pagingSelect.append(" ) row_ [color=red])[/color] where rownum_ <= ? and rownum_ > ?");
        }
    

    红色部分 9i不带

    点赞 评论
  • iteye_3312
    iteye_3312 2012-11-30 23:05

    这都找出来了 nb

    点赞 评论

相关推荐