Multi-attribute sequencing in spring data JPA---Nursing home management system involves technical arrangement

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.