Results 1 to 2 of 2

Thread: How to create a " Comparable Specification" and "in Specification" in Spring-Data

  1. #1
    Join Date
    Sep 2011
    Posts
    2

    Default How to create a " Comparable Specification" and "in Specification" in Spring-Data

    I see the Spring-Data's test case show the code to create Specification:

    Code:
    	private static <T> Specification<T> simplePropertySpec(final String property, final Object value) {
    
    		return new Specification<T>() {
    
    			public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
    
    				return builder.equal(root.get(property), value);
    			}
    		};
    	}
    Code:
    public static Specification<User> userHasFirstnameLike(final String expression) {
    
    		return new Specification<User>() {
    
    			public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
    
    				return cb.like(root.get("firstname").as(String.class), String.format("%%%s%%", expression));
    			}
    		};
    	}
    Question :
    How can i buld Specification like this :

    Code:
    	private static <T> Specification<T> greaterThan(final String property, final Object value) {
    
    		return new Specification<T>() {
    
    			public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
                                                      //How to return greeterThan Specification ,Eg: property (age) value(26)
                                                     // and in  Specification 
                                     // return builder.greaterThan 		
    	}
    		};
    	}

    I wait you answer online!

  2. #2
    Join Date
    Sep 2011
    Posts
    2

    Default

    By the way
    I want to create a common method to build the Specification to a query page

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •