Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring数据REST:忽略排序参数_Java_Spring_Spring Data Jpa_Spring Data_Spring Data Rest - Fatal编程技术网

Java Spring数据REST:忽略排序参数

Java Spring数据REST:忽略排序参数,java,spring,spring-data-jpa,spring-data,spring-data-rest,Java,Spring,Spring Data Jpa,Spring Data,Spring Data Rest,springboot2.0.1.RELEASE项目包含springdatajpa和springdatarest。REST端点中的sort参数似乎被忽略了(但相同的存储库方法在单元测试中也起作用)。 存储库如下所示: @RepositoryRestResource(collectionResourceRel = "orders", path = "orders") public interface OrderRepository extends PagingAndSortingRepository

springboot2.0.1.RELEASE项目包含springdatajpa和springdatarest。REST端点中的
sort
参数似乎被忽略了(但相同的存储库方法在单元测试中也起作用)。 存储库如下所示:

@RepositoryRestResource(collectionResourceRel = "orders", path = "orders")
public interface OrderRepository extends PagingAndSortingRepository<OrderEntity, Integer>, OrderRepositoryExtended {

@Query(value = "FROM OrderEntity a WHERE "
                + " (a.orderDateTime BETWEEN :dateFrom AND :dateTo) AND"
                + " ("
                + "  :searchTerm IS NULL OR"
                + "  (LOWER(a.customer.companyName) LIKE '%' || LOWER(:searchTerm) || '%') OR"
                + "  (LOWER(a.orderCode) LIKE '%' || LOWER(:searchTerm) || '%')"
                + " )"
)
Page<OrderEntity> findByOrderDateTimeBetweenAndSearchTerm(
        @RequestParam(name = "dateFrom")
        @Param("dateFrom")
        @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
            LocalDateTime dateFrom,

        @RequestParam(name = "dateTo")
        @Param("dateTo")
        @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
            LocalDateTime dateTo,

        @RequestParam(name = "searchTerm")
        @Param("searchTerm")
            String searchTerm,

        Pageable pageable);
当我尝试使用导出的REST端点调用它时,例如:

sort
参数被忽略,正如您在生成的查询中所看到的那样(为清晰起见进行了编辑):

我已经尝试过简化WHERE表达式,删除了类似的条件,但没有成功


谢谢

您物业的“导出”名称为
date\u order
。不仅在json请求中,而且在请求参数中都应该这样使用它

@Column(name = "DATE_ORDER")
@JsonProperty("date_order")
private LocalDateTime orderDateTime;
试着这样做:


(sort=date\u order

您是否尝试将sort参数放在url的末尾?您是否尝试过另一个字段进行排序?我制作了一个简单的演示示例,meI尝试将排序放在URL的前面和末尾;项目中的其他存储库可以很好地处理类似的情况。我从来没有按LocalDateTime字段排序过。LocalDateTime对我来说很有吸引力。试着用sort做一个简单的例子。顺便说一句,您可以从find方法中删除许多不必要的注释。Just@Param is mandatory我试过了,但是Hibernate生成的查询仍然没有order by参数。
select orderentit0_.id_order as id_order1_21_
...
from t_orders orderentit0_ 
cross join t_customers customeren1_ 
where 
    orderentit0_.id_customer=customeren1_.id_customer and 
    (orderentit0_.date_order between ? and ?) and 
    (? is null or lower(customeren1_.company_name) like concat('%'
lower(?)
'%') or lower(orderentit0_.order_code) like concat('%'
lower(?)
'%')) limit ?
@Column(name = "DATE_ORDER")
@JsonProperty("date_order")
private LocalDateTime orderDateTime;