Spring data query dsl how to add order by?

e2rabi :

I'm new to queryDsl,I'm working on Spring data query dsl to make a dynamic filter ,I use the interface : QueryDslPredicateExecutor so I can filter data using different entity fields ,now I want to add an order by to my query based on an BooleanExpression

This my code :

 QPersonData _personInventory = QPersonData.personData;
 BooleanBuilder query = new BooleanBuilder(); 

 query.and(_personInventory .status.eq(status));

Then I called my respository interface using the query :

personInventoryRepository.findAll(query,pageable);   

My question how I can apply order by to my query object based on different fields on my entity ?

e2rabi :

Thanks all finally this solution work for me :

 QPersonData _personInventory = QPersonData.personData;
 BooleanBuilder query = new BooleanBuilder(); 

 query.and(_personInventory .status.eq(status));
 personInventoryRepository.findAll(query,0, Integer.MAX_VALUE,new QSort(_personInventory.field1.asc(),_personInventory.field2.asc()));   

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=112082&siteId=1