spring数据jpa多次排序 [英] spring data jpa multiple sorting

查看:183
本文介绍了spring数据jpa多次排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用spring数据jpa和JQGrid.我需要基于多个排序参数的响应. 我尝试使用sort parameter = column a,column b和sort order = asc,但出现异常

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

:在pojo中找不到属性列a,列b.

: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);

如何在sortColName参数中传递多个列名?

How can I pass multiple column names in sortColName parameter?

推荐答案

在Spring Data中,您只需将Sort参数添加到findBy *方法中.排序对象有几个构造函数,例如

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)

其中Order具有属性和方向:Order(Direction direction, String property)

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

这篇关于spring数据jpa多次排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆