如何将 spring 数据排序转换为 querydsl OrderSpecifier? [英] How can I convert a spring data Sort to a querydsl OrderSpecifier?
本文介绍了如何将 spring 数据排序转换为 querydsl OrderSpecifier?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这基本上与此相反:如何使用 Spring JPA 进行分页 QueryDSL 查询?
这是针对我无法使用任何 findAll() 方法的自定义查询.
This is for a custom query for which i can't use any of the findAll() methods.
发错链接了.现在更正了.
Posted the wrong link. Now corrected.
推荐答案
您可以执行以下操作:但请确保修剪 o.getProperty() 以便您只传递属性而不是别名".+财产
You can do somethings like this: But make sure to trim the o.getProperty() so you only pass the property and not "alias."+property
if (pageable != null) {
query.offset(pageable.getOffset());
query.limit(pageable.getPageSize());
for (Sort.Order o : pageable.getSort()) {
PathBuilder<Object> orderByExpression = new PathBuilder<Object>(Object.class, "object");
query.orderBy(new OrderSpecifier(o.isAscending() ? com.mysema.query.types.Order.ASC
: com.mysema.query.types.Order.DESC, orderByExpression.get(o.getProperty())));
}
}
这篇关于如何将 spring 数据排序转换为 querydsl OrderSpecifier?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文