[英]Spring-Data-JPA paging
我使用Datatables jQuery插件来显示orderpositions列表。 在调试我的应用程序时,我偶然发现了以下不一致之处。
为了检索数据,我使用@Query
-Notation进行自定义查询:
@Query("select op from OrderPosition " +
"op where op.order.created >= ?1" +
" and op.depot in ?2" +
" and op.order.deliveryAddress.deliveryMode in ?3" +
" and op.pickStatus in ?4 and op.order.id like ?5 ")
Page<OrderPosition> findOrderpositionsByFilterStatus(Date date, List<Integer>depots, List<DeliveryMode> deliveryModes, List<ArticleStatusType> pickStatus, String sSearch, Pageable p);
发生的错误如下:
我有一套81个Orderpositions测试数据。 在前端,我可以按几个标准过滤。 其中一个标准是deliveryMode
(express | standard)。 我一次显示10个条目。 express
的总数为6.当通过页面进行翻页时,仅显示2 express
。 当明确地过滤express
我得到的所有6。
当我添加某种排序时,例如:
@Query("select op from OrderPosition " +
"op where op.order.created >= ?1" +
" and op.depot in ?2" +
" and op.order.deliveryAddress.deliveryMode in ?3" +
" and op.pickStatus in ?4 and op.order.id like ?5 " +
"order by op.order.id desc")
Page<OrderPosition> findOrderpositionsByFilterStatus(Date date, List<Integer>depots, List<DeliveryMode> deliveryModes, List<ArticleStatusType> pickStatus, String sSearch, Pageable p);
我得到了所有6个人。
是什么让我想到了这个问题:
当使用非注释查询 - 通用findAll()
或来自方法名称的查询时,Spring-Data-JPA在检测到pageable
是否在内部使用-clause order by
? 或者反过来:当使用pageable
时,我是否必须在每个自定义查询中使用-clause添加order by
?
是的。 如果不进一步指定,Spring Data使用OrderBy
(使用默认desc)。 查看日志:
SELECT t0.oid, t0.jpaversion, t0.amount, [...]
FROM [...]
WHERE [..] AND (t13.jpatype IS NULL OR t13.jpatype IN (?))
ORDER BY t0.oid DESC LIMIT ?, ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.