qq_37591811
qq_37591811
2017-06-22 07:57

求教 spring data jpa 分页排序的问题.

5
  • spring
  • 分页
  • jpa

现在项目中使用spring data jpa做分页排序时遇到这样一个问题,
有两个类Customer 和CustomerNode, 一对一关系. CustomerNode为Customer的一个属性.
Customer将一些蛋疼的少用的数据保存在CustomerNode中, 比方说intentionCurrent(顾客当前意向).
然后现在一个customer的table需要以CustomerNode.intentionCurrent的值来排序分页.
就会出现传入的页码和其他条件完全正确的情况下,无论怎么翻页, 页面内容不变的情况.

代码如下:
业务层:
Sort sort = new Sort(new Order(Direction.ASC, "CustomerNode.intentionCurrent"));

Pageable pageable = new PageRequest(pageNumber, pageSize, sort);

page = customerRepository.getAuthorityAllCustomer((User) null, search, pageable);

Repository:
@Query(value = "select c from Customer c where"
+ " c.enabled = true and (:user is null or c.marketer = :user or c.impler = :user)"
+ " and (c.name like :search or c.shortName like :search or c.oldName like :search"
+ " or exists (select 0 from User u where (u = c.marketer or u = c.impler) and u.name like :search)"
+ " or exists (select 0 from District d where d = c.province and d.name like :search)"
+ ")")
public Page getAuthorityAllCustomer(
@Param("user") User user,
@Param("search") String search,
Pageable page
);
重新截个图
图片说明
图片说明
图片说明

这种以属性的属性(customer.customerNode.intentionCurrent)的方式排序翻页后始终显示相同数据.

之后也尝试过联表,
Sort改为:
Sort sort = new Sort(new Order(Direction.ASC, "cn.intentionCurrent")
SQL第第一排改为:
@Query(value = "select c from Customer c, CustomerNode cn where cn.custo
mer = c "

编译无法通过

求教这种情况要如何处理?是以属性的属性的方式排序?还是联表? 还是用其他方式?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答

为你推荐