时间:2021-07-01 10:21:17 帮助过:3人阅读
serviceImp:
public Specification<TranxLog> getSpecFromDatesAndExample( LocalDateTime from, LocalDateTime to, Example<TranxLog> example) { return (Specification<TranxLog>) (root, query, builder) -> { final List<Predicate> predicates = new ArrayList<>(); if (from != null) { predicates.add(builder.greaterThan(root.get("dateField"), from)); } if (to != null) { predicates.add(builder.lessThan(root.get("dateField"), to)); } predicates.add(QueryByExamplePredicateBuilder.getPredicate(root, builder, example)); return builder.and(predicates.toArray(new Predicate[predicates.size()])); } };
..
public Page<TranxLog> findAllByConditions(TranxReportFormModel formModel, Pageable page) { ExampleMatcher matcher = ExampleMatcher.matching() .withNullHandler(ExampleMatcher.NullHandler.IGNORE) .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING) .withIgnoreCase() .withIgnoreNullValues(); Example<TranxLog> example = Example.of(formModel.getTranxLog(), matcher); return tranxlogRepository.findAll(getSpecFromDatesAndExample(from, to, Example.of(formModel.getTranxLog(), matcher)), page); }
spring data jpa 动态查询(mysql)
标签:ble omd cal over dex final service time mys