java - 如何在 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 是升序或降序的顺序。
解决方案
推荐阅读
- react-native - 如何使用标签导航器在一页中创建两个抽屉
- java - 尝试使用 sendkeys 无法上传文件?
- postgresql - 如何在 postgres 结束后立即刷新物化视图
- wordpress - PHP Mailer(可重复使用的表单)- 使用 Wordpress:效果很好,除了文件附件
- apache-kafka - kafka-consumer-groups 命令问题
- pytorch - Pytorch 不使用 GPU 。在 Fastai 工作
- android-studio - android studio 错误“无法下载 builder.jar”
- mysql - 查找唯一列的计数
- php - 从多维数组php创建不同的数组集
- java - 表未映射休眠