【问题标题】:Spring data group by with Specification and Paging support具有规范和分页支持的 Spring 数据组
【发布时间】:2022-06-10 22:11:58
【问题描述】:

我有一个基于“项目”的视图,其中一个项目属于一个容器,一个容器由多个项目组成。此外,一个项目有一个位置,多个项目可以有相同的位置。

数据库视图:

id_item   id_container   id_location   container_name   container_code   amount
'I1'      'C1'           'L1'          'container #01'  'c01'            10
'I2'      'C1'           'L1'          'container #01'  'c01'             5
'I3'      'C1'           'L2'          'container #01'  'c01'            25
'I4'      'C2'           'L3'          'container #02'  'c02'            30

我想选择按容器分组:

按容器划分的实体组:

@Entity
public class GroupByContainerEntity {
    private String idContainer;
    private String containerName;
    private String containerCode;
    private List<String> locations; // OR private String locations; -> comma separated ids
    private Integer sumAmount;
}

存储库:

public interface IGroupByContainerRepository extends JpaRepository<GroupByContainerEntity, String>, JpaSpecificationExecutor<GroupByContainerEntity> {
}

我需要传递额外的规范(例如仅某些位置和容器)和分页(例如按容器名称排序),因此(本机)查询方法不起作用:

groupByContainerRepository.findAll(Specification, Pageable)

有没有办法加载按容器分组的数据(通过spring数据存储库)? 规范和分页支持是强制性的。

【问题讨论】:

  • 后端分页需要使用唯一的排序键。你能认出一个吗?如果不能,支持分页将无法正常工作。

标签: java sql hibernate spring-data-jpa


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-09
  • 2015-01-21
  • 2015-06-15
  • 2017-01-29
  • 2014-12-21
  • 2019-08-31
相关资源
最近更新 更多