Announcement Announcement Module
Collapse
No announcement yet.
how to use JpaSpecificationExecutor ?? I'm new thank you Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to use JpaSpecificationExecutor ?? I'm new thank you

    in docs i see this

    public class CustomerSpecs {

    public static Specification<Customer> isLongTermCustomer() {
    return new Specification<Customer>() {
    Predicate toPredicate(Root<T> root, CriteriaQuery<?> query,
    CriteriaBuilder builder) {

    LocalDate date = new LocalDate().minusYears(2);
    return builder.lessThan(root.get(Customer_.createdAt), date);
    }
    };
    }


    public static Specification<Customer> hasSalesOfMoreThan(MontaryAmount value) {
    return new Specification<Customer>() {
    Predicate toPredicate(Root<T> root, CriteriaQuery<?> query,
    CriteriaBuilder builder) {

    // build query here
    }
    };
    }
    }



    and use it
    List<Customer> customers = customerRepository.findAll(isLongTermCustomer());

    my question is isLongTermCustomer() is a static method ,why used it like this?
    i think that it used like CustomerSpecs.isLongTermCustomer()

    There are other reasons

    who can give me a demo,thank you very much
Working...
X