首页 > 解决方案 > 如何在 jpa Query 中动态传递订单?

问题描述

我已经在我的 EmployeeRepository 中编写了这个查询。

 @Query(value="select * from employee e where e.is_active=?1 order by ?2 ?3 LIMIT ?5 offset ?4",nativeQuery = true)
    public List<Employee> findAllBySorting(@Param("isActive") boolean isActive, @Param("sortDataField") String sortDataField,
            @Param("sortDataOrder") String sortDataOrder,@Param("startIndex") int startIndex, @Param("count") int count);

运行此代码时收到此错误消息。

"ERROR","logger":"org.hibernate.engine.jdbc.spi.SqlExceptionHelper","msg":"ERROR: syntax error at or near \"$3\"\n  Position: 89"  

这里 sortDataField 是我需要对其应用排序的列名,而 sortDataOrder 是升序或降序的顺序。

标签: javasqlspringjpahql

解决方案


推荐阅读