具有多个In条件的Spring CrudRepository查询

问题描述 投票:0回答:1

我正在尝试使用Spring Data从dynamodb表中获取数据,使用In关键字过滤两个字段,但它总是返回空结果。

我有一个像这样的实体:

@DynamoDBTable(tableName = "my-table")
public class MyEntity {
    @Id
    private MyTableKey id;

    private String saleDate;
    private Long sellerId;

    // Some other properties

    @DynamoDBHashKey
    public String getSaleDate() {
        return this.saleDate;
    }

    @DynamoDBRangeKey
    public Long getSellerId() {
        return this.sellerId;
    }
}

我的存储库界面是

@EnableScan
@EnableScanCount
public interface MySalesRepository
        extends PagingAndSortingRepository<MyEntity, MyTableKey> {

    Page<MyEntity> findById (MyTableKey id, Pageable pageable);

    Page<MyEntity> findAllBySaleDateAndSellerIdIn (List<String> saleDate,
            List<Long> sellerId, Pageable pageable);
}

我想获得在saleDate列表中同时包含saleDate且在sellerId列表中同时包含sellerId的商品,但我得到0结果。

如何使用And和In关键字获取我想要的值?

java spring-boot spring-data-jpa spring-data amazon-dynamodb
1个回答
3
投票

尝试改变这个:

 Page<MyEntity> findAllBySaleDateAndSellerIdIn (List<String> saleDate,
        List<Long> sellerId, Pageable pageable);

对此:

 Page<MyEntity> findBySaleDateInAndSellerIdIn (List<String> saleDate,
        List<Long> sellerId, Pageable pageable);
© www.soinside.com 2019 - 2024. All rights reserved.