检查两个其他日期之间的日期春季数据jpa
我有这个型号:
public class Event { private String name; private Date start; private Date end; }
和存储库为
@Repository public interface EventRepository extends JpaRepository { List findByEventTypeAccount(Account account); }
我想要做的是,我将通过一个日期并且需要检查日期是否在start
和end
之间例如(我将在9月30日作为日期通过,并且需要查找在其start
和end
之间的所有条目)
像findDateisBetweenStartAndEnd(Date date)
类的东西?
你应该看看参考文档 。 这是很好的解释。
在你的情况下,我认为你不能使用之间,因为你需要传递两个参数
介于 – findByStartDateBetween …其中x.startDate介于?1和?2之间
在您的情况下,请查看使用LessThan
或LessThanEqual
与GreaterThan
或GreaterThanEqual
- 每种不超过/ LessThanEqual
LessThan – findByEndLessThan …其中x.start <?1
LessThanEqual findByEndLessThanEqual …其中x.start <=?1
- GREATERTHAN / GreaterThanEqual
GreaterThan – findByStartGreaterThan …其中x.end>?1
GreaterThanEqual – findByStartGreaterThanEqual …其中x.end> =?1
您可以使用运算符And
和Or
来组合两者。
我确实使用了以下解决方案:
findAllByStartDateLessThanEqualAndEndDateGreaterThanEqual(OffsetDateTime endDate, OffsetDateTime startDate);