检查两个其他日期之间的日期春季数据jpa [英] Check date between two other dates spring data jpa
问题描述
我有这个型号:
public class Event {
private String name;
private Date start;
private Date end;
}
和存储库
@Repository
public interface EventRepository extends JpaRepository<Event, Long> {
List<Event> findByEventTypeAccount(Account account);
}
我想做的是,我将通过一个日期并需要检查该日期介于开始
和结束
之间(例如,我将在9月30日作为日期通过,并需要找到所有条目9月30日他们的开始
和结束
)
What I want to do is, I will pass one date and need to check that date is between start
and end
eg(i will pass sept 30 as date and need to find all entries which have sept 30 between their start
and end
)
东西喜欢 findDateisBetweenStartAndEnd(日期日期)
?
推荐答案
你应该看看参考文档。很好地解释了。
You should take a look the reference documentation. It's well explained.
在你的情况下,我认为你不能使用它们因为你需要传递两个参数
In your case, I think you cannot use between because you need to pass two parameters
介于之间 - findByStartDateBetween ...其中x.startDate介于?1和?2
Between - findByStartDateBetween … where x.startDate between ?1 and ?2
在你的情况下,看看使用 LessThan
或 LessThanEqual
与 GreaterThan的组合
或 GreaterThanEqual
In your case take a look to use a combination of LessThan
or LessThanEqual
with GreaterThan
or GreaterThanEqual
- LessThan / LessThanEqual
- LessThan/LessThanEqual
LessThan - findByEndLessThan ...其中x.start< ?1
LessThan - findByEndLessThan … where x.start< ?1
LessThanEqual findByEndLessThanEqual ...其中x.start< =?1
LessThanEqual findByEndLessThanEqual … where x.start <= ?1
- GreaterThan / GreaterThanEqual
- GreaterThan/GreaterThanEqual
GreaterThan - findByStartGreaterThan ...其中x.end>?1
GreaterThan - findByStartGreaterThan … where x.end> ?1
GreaterThanEqual - findByStartGreaterThanEqual ...其中x.end> =?1
GreaterThanEqual - findByStartGreaterThanEqual … where x.end>= ?1
您可以使用运营商和
和或
来合并两者。
You can use the operator And
and Or
to combine both.
这篇关于检查两个其他日期之间的日期春季数据jpa的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!