检查其他两个日期之间的日期 spring 数据 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);
}
我想要做的是,我将传递一个日期并需要检查该日期是否在 start
和 end
之间,例如(我将通过 9 月 30 日作为日期,并需要找到在 start
和 end
之间有 9 月 30 日的所有条目)
What I want to do is, I will pass one date and need to check that date is between start
and end
e.g. (I will pass Sept 30 as date and need to find all entries which have Sept 30 between their start
and end
)
类似于findDateisBetweenStartAndEnd(Date date)
?
推荐答案
你应该看看 参考文档.解释的很好.
You should take a look the reference documentation. It's well explained.
在你的情况下,我认为你不能使用 between 因为你需要传递两个参数
In your case, I think you cannot use between because you need to pass two parameters
Between - 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 - findByEndLessThan ... 其中 x.start1
LessThan - findByEndLessThan … where x.start< ?1
LessThanEqual findByEndLessThanEqual ... where x.start <= ?1
LessThanEqual findByEndLessThanEqual … where x.start <= ?1
- GreaterThan/GreaterThanEqual
GreaterThan - findByStartGreaterThan ... where x.end>?1
GreaterThan - findByStartGreaterThan … where x.end> ?1
GreaterThanEqual - findByStartGreaterThanEqual ... where x.end>= ?1
GreaterThanEqual - findByStartGreaterThanEqual … where x.end>= ?1
您可以使用运算符 And
和 Or
将两者结合起来.
You can use the operator And
and Or
to combine both.
这篇关于检查其他两个日期之间的日期 spring 数据 jpa的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!