问题情景:

   在联表查询时

    ```

// 两张表关联查询

Join<Project, Plan> planJoin =
root.join("plans", JoinType.LEFT);
predicates.add(cb.equal(
planJoin.get(ColumnConsts.SUPPLIER_ID), subjectId));
query.groupBy("id");
```
查询结果数据正确,TotalElements数量偏大。

追查源码到统计totalElement,是统计结果集的所有记录
```
private static long executeCountQuery(TypedQuery<Long> query) {

Assert.notNull(query, "TypedQuery must not be null!");

List<Long> totals = query.getResultList();
long total = 0L;

for (Long element : totals) {
total += element == null ? 0 : element;
}

return total;
}
```
解决办法:将
```
query.groupBy("id");
//换成
query.distinct(true);  
//去除重复数据即可
```
https://blog.csdn.net/huwentao_totti/article/details/81389882

相关文章:

  • 2022-12-23
  • 2021-10-09
  • 2021-04-08
  • 2022-12-23
  • 2021-11-01
  • 2021-06-24
  • 2021-09-02
  • 2022-12-23
猜你喜欢
  • 2022-01-03
  • 2021-12-19
  • 2022-02-17
  • 2021-12-18
  • 2021-05-20
  • 2021-10-10
  • 2022-12-23
相关资源
相似解决方案