我有一个要求,我需要通过分页来获取基于三个表的连接的记录(也有附加要求)。所以我写了一个 nativeQuery 来获取记录。以下是示例查询
@Query(value = "SELECT "
+ "a.GROUP_REF_ID as refId "
+ "count(case when c.STAT_CD in :userStatus then (c.grp_user_id) end) as numberOfUsers, "
+ "count(case when b.STAT_CD in :itemStatus then (b.grp_item_id) end) as numberOfItems "
+ "from grp a left join grp_item b on a.grp_id=b.grp_id left join grp_user c on a.grp_id=c.grp_id "
+ "where a.stat_cd in :status and a.co_id in :cids "
+ "group by a.GROUP_REF_ID,a.grp_nam,a.GRP_DESC,a.co_id,a.co_nam,a.CRTE_BY, "
+ "a.CRTE_DT,a.UPDT_BY,a.UPDT_DT ", countQuery = "select count(*) from grp where stat_cd in :status and co_id in :cids ", nativeQuery = true)
public Page<Object> findByStatusAndCompanyIdIn(@Param("status") String status, @Param("cids") List<Long> companyIds,
@Param("userStatus") List<GroupUserStatus> userStatus,
@Param("itemStatus") List<GroupItemStatus> itemStatus, Pageable pageable);
现在还要求这些记录要在选择部分的任何列上进行排序。因此,如果用户通过numberOfItems,记录将在其上进行排序。但是我在这里遇到了一个问题,因为如果我将Sort参数传递为numberOfItems,spring 会在前面加上一个a.,numberOfItems这会导致错误not able to find a.numberOfItems。
有没有办法可以阻止 spring 在创建查询时添加表别名Sort,或者我应该用不同的方法编写我的逻辑