Mongodb 如何在spring boot中使用mongo存储库按日期查询?

Mongodb 如何在spring boot中使用mongo存储库按日期查询?,mongodb,spring-boot,Mongodb,Spring Boot,我用mongo Repostory在spring boot中开发了一个应用程序。我使用的是spring数据jpa。我在许多表中声明createdDate为java中的Date util包,在db中的日期存储为ISO格式。当我使用mongo repositoryfindByCreatedDate(日期)进行查询时,不会给出任何结果 下面是我的模型课 @Document public class BarModel extends BaseEntity { @NotNull @Siz

我用mongo Repostory在spring boot中开发了一个应用程序。我使用的是spring数据jpa。我在许多表中声明createdDate为java中的Date util包,在db中的日期存储为ISO格式。当我使用mongo repositoryfindByCreatedDate(日期)进行查询时,不会给出任何结果

下面是我的模型课

@Document
public class BarModel extends BaseEntity {

    @NotNull
    @Size(min = 2, max = 140)
    String name;
    String address;
    String city;
    String state;
    String zipcode;
    String phone;
    String description;
    String primImage;
    @DBRef
    Location location;
    @DBRef
    List<Special> specials;

}

@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity {

    @Id
    private String id;

    @CreatedBy
    private String createdBy = getCurrentAuditor();

    @CreatedDate
    @DateTimeFormat(iso = ISO.DATE_TIME)
    private Date creationTime = new Date();

    @CreatedBy
    @LastModifiedBy
    private String modifiedBy = getCurrentAuditor();

    @CreatedDate
    @LastModifiedDate
    @DateTimeFormat(iso = ISO.DATE_TIME)
    private Date modificationTime = new Date();
}

@Transactional
public interface BarModelRepository extends MongoRepository<BarModel, String> {

    Page<BarModel> findByCreationTime(Pageable pageable, Date creationtime);

    public List<BarModel> findByCreationTime(Date from, Date to);
}
@文档
公共类BarModel扩展了BaseEntity{
@NotNull
@尺寸(最小值=2,最大值=140)
字符串名;
字符串地址;
字符串城市;
字符串状态;
字符串zipcode;
字符串电话;
字符串描述;
字符串图像;
@DBRef
位置;
@DBRef
列出特价商品;
}
@映射超类
@EntityListeners(AuditingEntityListener.class)
公共抽象类BaseEntity{
@身份证
私有字符串id;
@创造的
私有字符串createdBy=getCurrentAuditor();
@创建数据
@DateTimeFormat(iso=iso.DATE\u时间)
私有日期creationTime=新日期();
@创造的
@最后修改
私有字符串modifiedBy=getCurrentAuditor();
@创建数据
@最后修改日期
@DateTimeFormat(iso=iso.DATE\u时间)
私有日期修改时间=新日期();
}
@交易的
公共接口BarModelRepository扩展了MongoRepository{
PageFindByCreationTime(可分页、可分页、日期creationtime);
公共列表findByCreationTime(日期从,日期到);
}

您可以共享您的模型类吗上面的一个是我的模型我也给了存储库。您的方法名称应该是“findByCreationTime”如果您选中,您可以看到您的方法第一个参数应该是查询值,第二个参数是PageEnable您可以共享您的模型类吗上面的一个是我的模型我也提供了存储库。您的方法名称应该是“findByCreationTime”如果您选中,您可以看到您的方法,第一个参数应该是查询值,第二个参数是可分页的