简体   繁体   English

如何在不重复使用弹簧靴的情况下使用两个不同的日期参数?

[英]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.

相关问题 如何在具有两个相同日期的查询之间使用EJBQL? - How do I use a EJBQL between query with two identical dates? 如何检查两个日期是否在一个周期(间隔)之间? - How can I check that a two dates are between a period(interval)? 如何找到两个日期之间的年数? - How can I find the number of years between two dates? 如何找到两个日期之间的天数? - How can I find the number of days between two Dates? 计算两个日期结果之间的差异我只需要几个月和几天(没有年份) - Calculate different between two dates result I need months and days only (without Year) 在Java中两个不同日期之间打印日期 - printing dates between two different dates in Java 如何使用PixelGrabber(JAVA)来计算总像素并比较两个图像之间的不同像素 - How can I use PixelGrabber (JAVA) in order to count total pixels and compare different pixels between two images 在不使用任何日期类的情况下计算两个日期之间的天数 - Calculate days between two dates without using any date class 如何在两个日期之间获取数据REST Spring - How to get data between two dates REST Spring 如何使用 Hibernate &amp; Spring Data JPA 正确注释两个实体之间的这种关系? - How can I properly annotate this relationship between two entities using Hibernate & Spring Data JPA?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM