Example Analysis of SpringBoot JPA sort Multi-attribute sorting
This article mainly introduces SpringBoot JPA sort multi-attribute sorting example analysis, the article is very detailed, has a certain reference value, interested friends must read!
SpringBoot JPA sort Multi-attribute sorting
In developing JPA, you encounter situations where you need to sort data in multiple attributes, such as
select * from MldmasView order by vslName ASC,custName ASC,docDate DESC; import jar package import org.springframework.data.domain.Sort.Order; code examples List list = new ArrayList();Order order1 = new Order (Direction.ASC, "vslName"); Order order2 = new Order (Direction.ASC, "custName");Order order3 = new Order(Direction.DESC, "docDate");list.add(order1);list.add(order2);list.add(order3);Sort sort = Sort.by (list);final List mldmasViews = this.mldmasViewRepository .findAll(sort);
Finish sorting mldmasViews
Error reporting using Sort in a Sping Boot project
Today, when using Sort, the following error is displayed
'Sort(org.springframework.data.domain.Sort.Direction, java.util.List)' in 'org.springframework.data.domain.Sort'
has private access in
Check it out and say that it is springboot2.2.1 (inclusive) version Sort can no longer be instantiated, the construction method is already private!
Sort.by can be used instead to get the Sort object
The above is "SpringBoot JPA sort multi-attribute sorting example analysis" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!