List of usage examples for org.springframework.data.jpa.repository JpaSpecificationExecutor findAll
List<T> findAll(@Nullable Specification<T> spec);
From source file:org.pushio.webapp.support.persistence.SearchFilter.java
/** * @see List<BJob> jobs = SearchFilter.query("jName[like]=sma&jId=3&BEmployees.employeeId=2", BJob.class, jobsRepository); * @param query --> "jName[like]=sma&jId=3&BEmployees.employeeId=2" * @param entity --> BJob.class//from w w w. j a va 2 s. co m * @param repository --> jobsRepository JpaSpecificationExecutor * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static List query(String query, Class<?> entity, JpaSpecificationExecutor repository) { String strs[] = StringUtils.split(query, '&'); if (strs == null || strs.length == 0) { throw new IllegalArgumentException("query?null"); } else { Map<String, Object> searchParams = new HashMap<String, Object>(strs.length); // TreeMap?? for (String str : strs) { String keyValue[] = StringUtils.split(str, '='); if (keyValue.length != 2) { throw new IllegalArgumentException("\"" + query + "\"??"); } searchParams.put(StringUtils.trim(keyValue[0]), keyValue[1]); } Specification spec = DynamicSpecifications .bySearchFilter(SearchFilter.parse2Filter(searchParams).values(), entity); return repository.findAll(spec); } }