Spring 数据比较 2 个日期范围
Spring Data compare 2 date ranges
我需要比较一个日期范围内的预订(如果有的话)
例如,客户端发送 21-03-2018 到 25-03-2018,服务器 returns 所有不在数据库范围内的可用预订。
List<Booking> findByStarDateBetween(Date start, Date end);
List<Booking> findByEndDateBetween(Date start, Date end);
我必须进行自定义查询吗?
db table
Booking
int id;
Date startDate;
Date endDate;
你可以join the conditions。因此,您的代码将是:
List<Booking> results = findByStartDateBeforeAndEndDateAfter(startDate, endDate);
希望对您有所帮助。如果没有,请发表评论。
我需要比较一个日期范围内的预订(如果有的话) 例如,客户端发送 21-03-2018 到 25-03-2018,服务器 returns 所有不在数据库范围内的可用预订。
List<Booking> findByStarDateBetween(Date start, Date end);
List<Booking> findByEndDateBetween(Date start, Date end);
我必须进行自定义查询吗?
db table
Booking
int id;
Date startDate;
Date endDate;
你可以join the conditions。因此,您的代码将是:
List<Booking> results = findByStartDateBeforeAndEndDateAfter(startDate, endDate);
希望对您有所帮助。如果没有,请发表评论。