Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PageHelper5.3.2版本中LOCAL_PAGE没有及时清除 #733

Open
1 task
egene-huang opened this issue Mar 18, 2023 · 2 comments
Open
1 task

PageHelper5.3.2版本中LOCAL_PAGE没有及时清除 #733

egene-huang opened this issue Mar 18, 2023 · 2 comments

Comments

@egene-huang
Copy link

egene-huang commented Mar 18, 2023

  • 我已在 issues 搜索类似问题,并且不存在相同的问题.

异常模板

使用环境

  • PageHelper 版本: 5.3.2
  • 数据库类型和版本: mysql5.7
  • JDBC_URL: 基于mysql5.7 + Vitess

背景:
使用PageHelper.startPage(1, 10);方式分页

复现场景:

  1. 需要先分页查询 unc_app_with_user 表然后通过结果遍历 根据关联id查询 table_b 表(不分页)返回 unc_app_basic_info 结果
  2. unc_app_with_user在 serviceA中查询, unc_app_basic_info 在serviceB中查询 ,
  3. 在查询到unc_app_with_user结果集后,再根据id查询unc_app_basic_info 返回了两条数据 导致反序列化类型转换错误,因为其中一条不是自己表中的数据

说明:
检查过在mybatis mapper文件中字段等映射没有错误, 也没有明确需要关联查询

排查步骤:

  1. 在serviceB 查询unc_app_basic_info(根据id)前后 打印了 PageHelper.getLocalPage() 确定包含了查询unc_app_with_user的结果
  2. 解决办法:在查询unc_app_with_user后在finally中手动调用PageHelper.clearPage() 问题得到解决
  3. 类似代码
            Integer pageNum = param.getPageNum();
            Integer pageSize = param.getPageSize();
            boolean pagination = Objects.nonNull(pageNum) && Objects.nonNull(pageSize);
            if (pagination) {
                PageHelper.startPage(pageNum, pageSize);
            }
            List<AppWithUserEntity> entities = appWithUserMapper.selective(entity);
            if (entities.isEmpty()) {
                return null;
            }
            PageInfo<AppWithUserEntity> pageInfo = new PageInfo<>(entities);
            if (!pagination) {
                pageInfo.setList(entities);
                pageInfo.setTotal(entities.size());
            }
            return pageInfo;

PageHelper在项目中的配置:

    <plugins>
        <!-- PageHelper -->
        <plugin interceptor="com.github.pagehelper.PageInterceptor">
            <property name="dialect" value="com.github.pagehelper.dialect.helper.MySqlDialect"/>
            <property name="offsetAsPageNum" value="false"/>
            <property name="rowBoundsWithCount" value="true"/>
            <property name="pageSizeZero" value="true"/>
            <property name="reasonable" value="false"/>
            <property name="supportMethodsArguments" value="false"/>
        </plugin>
    </plugins>

原 SQL

03-18 17:34:39 http-nio-8001-exec-1[DEBUG][xx.xx.xx#debug:137]MYBATIS - ==>  Preparing: SELECT id,user_id, app_key,app_id, `desc`, role_id, creator,operator,insert_time,update_time,yn FROM unc_app_with_user WHERE 1=1 and yn=? and user_id=?
03-18 17:34:39 http-nio-8001-exec-1[DEBUG][xx.xx.xx#debug:137]MYBATIS - ==> Parameters: 1(Integer), xx(String)
03-18 17:34:39 http-nio-8001-exec-1[DEBUG][xx.xx.xx#debug:137]MYBATIS - <==      Total: 1

debug:137]MYBATIS - ==>  Preparing: SELECT id,app_id, app_name, app_cn_name,app_desc,app_url,`source`,app_key,app_token,creator,operator,insert_time,update_time,yn FROM unc_app_basic_info WHERE 1=1 and app_id=? and yn=?
03-18 17:34:39 http-nio-8001-exec-1[DEBUG][xx.xx.xx#debug:137]MYBATIS - ==> Parameters: 1(String), 1(Integer)
03-18 17:34:39 http-nio-8001-exec-1[DEBUG][xx.xx.xx#debug:137]MYBATIS - <==      Total: 1
select * from xxx where xxx = xxx

期望的结果:

不用手动清理local

@pagehelper
Copy link
Owner

local使用过一次就会清理,不需要手动。。

还可以用 try(Page<Object> ignored = PageHelper.startPage(1, 10)) { 这种方式保证被清理

@suochuanlin
Copy link

并发情况下5.1.3 遇到过这个问题:
image
手动HandlerInterceptor清理的,可以看看

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants