spring data jpa multiple sorting

2019-07-07 10:45发布

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?

1条回答
Evening l夕情丶
2楼-- · 2019-07-07 11:25

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)

查看更多
登录 后发表回答