How to sort PageRequest on String as numeric value

前端 未结 3 1079
悲哀的现实
悲哀的现实 2021-01-12 00:51

I currently have a system in place which can filter and sort records in the database and return them as a Paged object. One of the lines is like this:

final          


        
3条回答
  •  一整个雨季
    2021-01-12 01:12

    I think you could try the Spring Data JpaSort class which allows function calls.

    As stated in the documentation you will have something like :

    @Query("select u from User u where u.lastname like ?1%")
      List findByAndSort(String lastname, Sort sort);
    
    repo.findByAndSort("targaryen", JpaSort.unsafe("LENGTH(firstname)"));
    

    You could also use it with a Pageable object.

提交回复
热议问题