Here's a way to introduce me:
The first step, the lead package
Import Org.springframework.data.domain.Sort;
Import Org.springframework.data.domain.Sort.Order;
The second step, the service method code
@Override
Public page<turnoverrecord> findAll (integer pagenum, integer pageSize, Turnoverrecord turnoverrecord) {
First press isturnover from small to large ascending, then press Turnovertime Ascending
list< order> orders=new arraylist< order> ();
Orders.add (New Order (sort.direction). ASC, "Isturnover"));
Orders.add (New Order (sort.direction). ASC, "Turnovertime"));
pageable pageable= New Pagerequest (PageNum-1, PageSize, new Sort (orders));
specification<turnoverrecord> specification = new specification<turnoverrecord> () {
@Override
Public predicate topredicate (root<turnoverrecord> Root, criteriaquery<?> query, Criteriabuilder CB) {
predicate predicate = cb.conjunction ();
Single-Attribute Ordering
Query.orderby (CB.ASC (Root.get ("Isturnover"));
Query.orderby (Cb.desc (Root.get ("id")));
Query.groupby (Root.get ("id"));
Query.distinct (TRUE);
Determine if there is a condition
Predicate.getexpressions (). Add (Cb.equal (Root.get ("flag"), 1));
if (Turnoverrecord! = null) {
if (Stringutil.isnotnull (Turnoverrecord.getmemberid ())
&& Stringutil.isnotnullandzero (Turnoverrecord.getmemberid (). GetId ())
) {
Predicate.getexpressions (). Add (Cb.equal (Root.get ("MemberID"). Get ("id"), Turnoverrecord.getmemberid (). GetId ());
}
if (Stringutil.isnotnull (Turnoverrecord.getmemberid ())
&& Stringutil.isnotnullandblank (Turnoverrecord.getmemberid (). GetName ())
) {
Predicate.getexpressions (). Add (Cb.like (Root.get ("MemberID"). Get ("name"), "%" +turnoverrecord.getmemberid (). GetName (). Trim () + "%"));
}
if (Stringutil.isnotnull (Turnoverrecord.getcreator ())
&& Stringutil.isnotnullandblank (Turnoverrecord.getcreator (). GetName ())) {
Predicate.getexpressions (). Add (Cb.like (Root.get ("creator"). Get ("name"), "%" +turnoverrecord.getcreator (). GetName (). Trim () + "%"));
}
}
return predicate;
}
};
Return Turnoverrecorddao.findall (specification, pageable);
}
Multi-attribute sequencing in spring data JPA---Nursing home management system involves technical arrangement