java—修改spring规范以在字符串列表中搜索

0tdrvxhp  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(130)

我有以下规格,工作正常:

Specification<TransactionRequestEntity> specification = Specification
                .where(specificationBySourceFundAccountId(requestDto.getSourceFundAccountId()))
                .and(specificationByReason(requestDto.getReason()))
                .and(specificationByAmount(requestDto.getAmount()))
                .and(specificationByMetadata(requestDto.getMetadata())
                        .and(specificationByDate(requestDto.getDate())));

        List<TransactionRequestEntity> transactionRequestEntities = transactionRequestsRepository
                .findAll(specification);

我试图优化查询,并传递一个原因字符串列表,而不是一个单一的原因,如果列表中的任何字符串匹配得到对象。这是规范的原因,也是预期的工作

public static Specification<TransactionRequestEntity> specificationByReason(String reason) {
        return (root, query, builder) -> builder.equal(root.get(REASON), reason);
}

因此,我试图用原因字符串列表替换原因字符串,但我不确定什么是最好的方法。它是一个查询,还是一个查询生成器。我还发现有in()方法,但到目前为止还不能使它工作

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题