问题
Can I give sort parameter not at the end expresion? Because i need use sort parameter inside over() function.
example:
@Query(value = "...?2...over(?4)...?1...?3")
myMethod(int a,int b,int c,Sort sort);
or expression for sort inside over: ,--#sort\n , #{#sort} ..
I still get :
java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.lang.Integer ...name of method.. (int,int,int,org.springframework.data.domain.Sort)!
回答1:
Parameters of type Sort
get special treatment by Spring Data JPA.
Even if that wouldn't be the case what you try to achieve can't be accomplished with a simple bind parameter, because bind parameters allowed in these places by SQL.
Depending on what you want to achieve you might be able to do something like the following:
@Query("select .... over(... order by CASE ?1 WHEN "first THEN first
WHEN 'last' THEN last
END")
public Something method(String columnNameForSorting)
assuming you have the columns first
and last
you want to switch between for sorting.
Standard SQL alternative to Oracle DECODE for more information about the CASE expression
来源:https://stackoverflow.com/questions/46861276/spring-data-using-sort-not-at-the-end