blinkfox / fenix

This is an extension library to the Spring Data JPA complex or dynamic SQL query. 这是一个比 MyBatis 更加强大的 Spring Data JPA 扩展库,为解决复杂动态 JPQL (或 SQL) 而生。https://blinkfox.github.io/fenix
https://blinkfox.github.io/fenix
Apache License 2.0
346 stars 72 forks source link

@QueryFenix 注解原生SQL的分页查询中没有去掉ORDER BY #67

Closed dorea closed 2 years ago

dorea commented 2 years ago

Hi, 如题, 在用这个注解的原生SQL查询时, 分页查询的SQL没有去掉ORDER BY语句. 目前可以通过加countQuery解决, 不清楚是否是BUG还是只支持JPQL

java方法:

@QueryFenix(resultType = OperationLogListVo.class, resultTransformer = UnderscoreTransformer.class, nativeQuery = true)
Page<OperationLogListVo> queryLogs(@Param("qv") QueryVo qv, Pageable page);

输入日志:

Hibernate: SELECT LOG.*, US.USER_CNAME AS USER_NAME FROM TL_OPERATION_LOG LOG LEFT JOIN TS_USER US ON US.USER_NO = LOG.CREATE_BY WHERE 1 = 1 ORDER BY LOG.CREATE_TIME DESC offset 0 rows fetch next ? rows only
Hibernate: select count(*) as count from  TL_OPERATION_LOG LOG LEFT JOIN TS_USER US ON US.USER_NO = LOG.CREATE_BY WHERE 1 = 1 ORDER BY LOG.CREATE_TIME DESC
blinkfox commented 2 years ago

@dorea 应该是你的写法有些问题吧,排序参数和分页参数一样,都应该写到 Pageable 里面,不要写到原生 SQL 里面,这样求总数的 SQL 里面就会把这两个参数单独隔离出来执行。

dorea commented 2 years ago

ok, 明白了.谢谢