blinkfox / fenix

This is an extension library to the Spring Data JPA complex or dynamic SQL query. 这是一个比 MyBatis 更加强大的 Spring Data JPA 扩展库,为解决复杂动态 JPQL (或 SQL) 而生。https://blinkfox.github.io/fenix
https://blinkfox.github.io/fenix
Apache License 2.0
345 stars 72 forks source link

建议getCountSql支持distinct #11

Closed masankin closed 3 years ago

masankin commented 4 years ago

问题说明: fenix/src/main/java/com/blinkfox/fenix/jpa/FenixJpaQuery.java 中 this.sqlInfo.getSql().replaceFirst(REGX_SELECT_FROM, SELECT_COUNT);

如果 this.sqlInfo.getSql() 查询为: select distinct t.id from t_user

会被替换成 select count(*) as count from t_user

这样导致 list 集合数据 和 count 总数不一样

正确替换sql应该为: select count(distinct t.id) as count from t_user

解决方案: 1.count查询 正则支持识别 distinct: 2.或者提供一个方法/注解属性,类似 countQuery ,能够手动控制是否使用 distinct

目前解决方法是用 countQuery 查询总数

blinkfox commented 4 years ago

@masankin 后续可以考虑支持,使用解决方案2 较为合适。

pengten commented 4 years ago

@masankin @blinkfox 根据你们的讨论,我试着做了一版:https://github.com/blinkfox/fenix/pull/24

pengten commented 4 years ago

@masankin 请问你们使用的fenix和jpa版本是多少呢?

blinkfox commented 3 years ago

这个 issue 新版本有了,我就关了哈