大于使用spring数据jpa和querydsl搜索

时间:2018-07-18 20:53:07

标签: spring-data-jpa querydsl

我对要搜索的字段编号大于,小于或等于,但找不到将搜索条件添加到参数的方法。

示例:

http://localhost:8080/api/report/shippedQty=30,gt

或:

http://localhost:8080/api/report/shippedQty=30[gt] 

或其他。问题是我无法将任何选项添加到shippedQty字段,因为它是一个整数字段。 Spring对此有解决方案吗?

@RepositoryRestResource(path = "/report", collectionResourceRel = "report", itemResourceRel = "report")
    public interface ReportRepository extends PagingAndSortingRepository<Report, Long>, QueryDslPredicateExecutor<Report>,
            QuerydslBinderCustomizer<QReport> {

@Override
default void customize(QuerydslBindings bindings, QReport report) {
    bindings.including(
            report.description,
            report.item,
            report.program,
            report.shippedQty,
    );
    bindings.excludeUnlistedProperties(true);

    SingleValueBinding<NumberPath<Integer>, Integer> numberPathContains = (path, value) -> path.stringValue().contains(value.toString());

    bindings.bind(firstFill.description).first(StringPath::containsIgnoreCase);
    bindings.bind(firstFill.item).first(StringPath::containsIgnoreCase);
    bindings.bind(firstFill.program).first(StringPath::containsIgnoreCase);
    bindings.bind(firstFill.shippedQty).first(numberPathContains);

 }
}

0 个答案:

没有答案