日期之间的 MongoRepository 查询 [英] MongoRepository query for between dates
本文介绍了日期之间的 MongoRepository 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 pojo
public class PacketData implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private final String token = UUID.randomUUID().toString();
private final ZonedDateTime arrived = ZonedDateTime.now();
}
我打算像下面这样使用.
I plan to use like following.
@Query("?")
List<PacketData> findPacketArrivedBetween(ZonedDateTime startDate, ZonedDateTime endDate);
有没有办法可以将以下查询放在上面的 query
注释中,以及如何做大于和小于逻辑
Is there a way i can put the following query to the above query
annotation and how i can do greater than and less than logic
Query query = new Query().addCriteria(Criteria.where("arrived").gte(startDate).lte(endDate));
推荐答案
您可以尝试以下几种方法.
You can try following couple of ways.
没有查询注释.
List<PacketData> findByArrivedBetween(ZonedDateTime startDate, ZonedDateTime endDate);
带有查询注释.
@Query("{'arrived': {$gte: ?0, $lte:?1 }}")
List<PacketData> findPacketArrivedBetween(ZonedDateTime startDate, ZonedDateTime endDate);
这篇关于日期之间的 MongoRepository 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文