簡體   English   中英

Spring 具有嵌套屬性標准支持的數據類型排序

[英]Spring Data TypedSort with nested property criteria support

我正在嘗試定義以下排序標准:

TypedSort<Task> typedSort = Sort.sort(Task.class);
Sort typedSortCriteria = typedSort.by(task -> task.getAssignee().getLastName())
    .descending();

但我得到一個編譯異常:

The method by(Function<Task,String>) is ambiguous for the type Sort.TypedSort<Task>

是否可以定義嵌套屬性類型的排序條件?

PS。 我向 Spring Data Commons 存儲庫提交了一個問題,以澄清這一點:

https://github.com/spring-projects/spring-data-commons/issues/2380

我的錯,看來我只需要明確地投射Function

typedSort.by((Function<Task, String>) task -> task.getAssignee().getLastName())
    .descending();

無論如何,希望這會有所幫助,因為目前沒有關於此特定案例的文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM