简体   繁体   中英

Spring Data TypedSort with nested property criteria support

I am trying to define the following sort criteria:

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

But I'm getting a compilation exception:

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

Is it possible to define a nested property typed sort criteria?

PS. I submitted an issue to the Spring Data Commons repository to clarify this point as well:

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

My bad, it seems I just had to cast the Function explicitly:

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

Hope this helps anyway, as there is no documentation about this particular case at this moment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM