1 package de.spring.example.persistence.domain.specifications;
3 import java.time.LocalDate;
5 //import javax.persistence.criteria.CriteriaBuilder;
6 //import javax.persistence.criteria.CriteriaQuery;
7 //import javax.persistence.criteria.Predicate;
8 //import javax.persistence.criteria.Root;
10 import org.springframework.data.jpa.domain.Specification;
12 import de.spring.example.persistence.domain.Ad;
14 public class AdSpectifications {
16 // public static Specification<Ad> createdToday() {
17 // return new Specification<Ad>() {
20 // public Predicate toPredicate(Root<Ad> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
21 // final LocalDate date = LocalDate.now();
23 // return cb.equal(root.get("createdAt"), date);
31 * The same using lambda expressions
33 public static Specification<Ad> createdToday() {
34 return (root, query, cb) -> {
35 final LocalDate date = LocalDate.now();
37 return cb.equal(root.get("createdAt"), date);
41 // public static Specification<Ad> mobileImage(String image) {
42 // return new Specification<Ad>() {
45 // public Predicate toPredicate(Root<Ad> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
47 // return cb.equal(root.get("adMobileImage"), image);
55 * The same using lambda expressions
57 public static Specification<Ad> mobileImage(String image) {
58 return (root, query, cb) -> {
59 return cb.equal(root.get("adMobileImage"), image);