我用mongo reposotory在spring boot中开发了一个应用程序。我正在使用spring数据jpa。我在许多表中声明了createDate作为日期工具包在java中,而日期存储在db中作为ISO格式。当我使用mongo存储库 findByCreatedDate(日期日期)查询时,没有结果。
以下是我的模型类
@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);
}