-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
springboot多数据源 配置对应数量的PageInterceptor 导致重复查询问题? #166
Comments
按理说配置多个应该没问题。。 能不能发个执行分页的完整日志(含SQL)。 |
看到你的回复我就又跑了一次@test,惊奇的发现不配置好像可以,因为前面我发现会重复查询,就把加入PageInterceptor到SqlSessionFactoryBean的部分去掉,然后不用PageHelper,今天测试开始就加上了PageHelper.offsetPage(0, 10); 然后跑下面代码能够生效。 @Test
public void testOracle() {
PageHelper.offsetPage(0, 10);
List<VYktCardinfo> vYktCardinfos = vYktCardinfoMapper.selectByExample(null);
PageInfo<VYktCardinfo> pageInfo = new PageInfo<>(vYktCardinfos); //取分页信息
for (int i = 0; i < pageInfo.getList().size(); i++) {
// if (vYktCardinfos.get(i) instanceof VYktCardinfo) {
log.debug(vYktCardinfos.get(i) + "");
// }
}
} 日志在这里: |
你用pagehelper-starter了吗? 直接用starter,配置动态获取数据库类型就能用。 |
具体要配置配置自动切换 dialect啊,需要自己写切面吗?
}` 而自动配置不能配置出两种类型吧,不能这么配啊 pagehelper.helperDialect=oracle,mysql
|
@jht385 配置多数据源code能发我看下吗? |
@xiaomozhang 我用的是分目录方式(另一种是切面的方式),目录区分mapper目录,配置注入不同DataSource,DataSource在生成对应的SqlSessionFactory->SqlSessionTemplate ` @bean(name = "mysqlDataSource") 然后PageInterceptor在应用启动时就遍历SqlSessionFactory为每个SqlSessionFactory添加上了配置的或默认的,那么不同数据库执行时用同一种类型的PageInterceptor应该是会出错的,你有什么解决办法吗? |
我这的需求是从一个oracle库读数据,写到mysql库
pagehelper 5.1.2
mybatis-spring-boot-starter 1.3.1
数据源我采用分目录的方式
SqlSessionFactory 配置对应的PageInterceptor
查询会出现的问题
1.查询数量会翻倍
2.查询结果,第一个元素会变成long,数据是总数,为了保证运行我要instanceof 判断一下,但这样肯定不对
如下查询的结果会变成:
[15598, com.xx.bean.oracle.VYktCardinfo@40c76f5a, com.xx.bean.oracle.VYktCardinfo@a323a5b, 15598, com.xx.bean.oracle.VYktCardinfo@40c76f5a, com.xx.bean.oracle.VYktCardinfo@a323a5b]
这种需求能支持到吗
The text was updated successfully, but these errors were encountered: