【发布时间】:2020-10-04 19:11:14
【问题描述】:
我想先声明一下,我知道已经有一个排序函数,可以这样调用它:
http://localhost:8080/api/person?sort=name,ASC
但是,由于我依赖于多个域,我目前无法使用这种排序类型。由此我决定制作一个自定义排序参数,如下所示:
http://localhost:8080/api/person?ordering=name
然后我决定查看我的存储库以创建一个自定义 JPQL,它可用于在调用上面的 URL 时对我的值进行排序:
回购方法:
@Query("SELECT p FROM DePerson p, DeClass c, DeSchool s" +
"WHERE p.personId = c.id " +
"AND p.schoolId = s.id " +
"ORDER BY :ordering")
Page<DeSiteUser> orderingAll(@Param("ordering") String ordering, Pageable pageable);
服务方法:
Page<DePerson> newPage = repository.orderingAll(ordering, pageable);
List<DePerson> personList = newPage.getContent();
for (DePerson person: personList ) {
result.add(convertDTO(person));
}
return new PageImpl<>(result, pageable, page.getTotalElements());
从这里我调用了它,现在得到了这个错误:
There was an unexpected error (type=Internal Server Error, status=500).
could not extract ResultSet; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet
我想问两个问题。 1. 这是使用 ORDER BY 生成自定义排序参数的正确途径吗? 2. 为什么会出现错误。谢谢。
【问题讨论】: