[英]How I can use two dates parameters for two different between without repeat using spring boots?
I'm new at spring boots, and I'm trying use it for a query, I'll use 2 instant parameters, and use this instant to compare them to two instant of my object (DateBegin and StartedWork).我是 spring boots 的新手,我正在尝试将它用于查询,我将使用 2 个即时参数,并使用此即时将它们与我的对象的两个即时(DateBegin 和 StartedWork)进行比较。 The code below work, but for that I have to send two times my first date and last date.下面的代码有效,但为此我必须发送两次我的第一次约会和最后一次约会。
@Transactional(readOnly = true)
Collection<MyClass> findByDateBeginBetweenOrStartedWorkBetween (Instant firstDate, Instant lastDate, Instant firstDateAgain, Instant lastDateAgain);
I can't find an example of that situation.我找不到这种情况的例子。 I try things like that:我尝试这样的事情:
@Transactional(readOnly = true)
Collection<MyClass> findByDateBeginOrStartedWorkBetween (Instant firstDate, Instant lastDate);
But i get the error below at build:但是我在构建时收到以下错误:
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.Collection com...MyClass.findByDateBeginOrStartedWorkBetween (java.time.Instant,java.time.Instant)!引起:java.lang.IllegalArgumentException:无法为方法公共抽象java.util.Collection com...MyClass.findByDateBeginOrStartedWorkBetween(java.time.Instant,java.time.Instant)创建查询! No parameter available for part startedWork BETWEEN (2): [IsBetween, Between] NEVER.没有参数可用于部分开始工作 BETWEEN (2): [IsBetween,Between] NEVER。
Can I use and how I can use just one time each date parameter in spring boots?我可以使用以及如何在春季靴子中使用每个日期参数一次吗?
You could keep the first one so it works with how Spring Data derives queries, but define the second method as a default method for your convenience:您可以保留第一个,以便它与 Spring Data 派生查询的方式一起使用,但为了方便起见,将第二个方法定义为默认方法:
Collection<MyClass> findByDateBeginBetweenOrStartedWorkBetween(Instant firstDate, Instant lastDate, Instant firstDateAgain, Instant lastDateAgain);
default Collection<MyClass> findByDateBeginOrStartedWorkBetween(Instant firstDate, Instant lastDate) {
return findByDateBeginBetweenOrStartedWorkBetween(firstDate, lastDate, firstDate, lastDate);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.