Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring data jpa multiple sorting

I am using spring data jpa and JQGrid. I need response based on multiple sort parameters. I tried using sort parameter=column a,column b and sort order=asc but I am getting an exception

:No property column a,column b found in pojo.

It works if I would pass either of one columns as sort parameter. Code:

Pageable pageable = JPAUtility.constructPageSpecification(pageNumber, rowsPerPage, sortColName, sortOrder);

How can I pass multiple column names in sortColName parameter?

like image 210
abii Avatar asked Aug 30 '25 17:08

abii


1 Answers

In Spring Data you just need to add Sort parameter into findBy* method. Sort object has got a couple constructors, e.g.

Sort(Direction direction, String... properties)

which is probably exactly what you need. If you need to specify different directions for various properties then you can use

Sort(Order... orders)

where Order has property and direction: Order(Direction direction, String property)

like image 165
Jakub Kubrynski Avatar answered Sep 02 '25 16:09

Jakub Kubrynski