在特定日期范围内由createdAt查询实体元素不起作用

问题描述 投票:-1回答:1

我的实体创建了createdAt字段,该字段在创建实体时由@CreatedDate填充。此属性是Date类型。

class MyEntity {
    @CreatedDate
    private Date createdAt;
}

我想过滤掉List中从startDate到endDate范围内的所有实体。问题是,当我使用findAllByCreatedAtBetween(Date startDate, Date endDate);时,它可以工作,但不适用于所有情况。创建实体时,即:2019-10-25 14:15:23当用户从2019-10-24 00:00 endDate到2019-10-25键入@RequestParam startDate时,我也想获取它14:15并且也采取这个实体。我怎么能忽略几分钟之后的一切?有一种方法,因为当我将这些值作为startDate和endDate传递时,找不到该实体,要找到它,我必须将14:15更改为14:16。

spring spring-boot
1个回答
0
投票

您可以在LocalDateTime中设置任何参数而无需其他参数。例如,您想要没有分钟的句柄。您可以这样设置搜索日期参数:

LocalDateTime localDateTime= myDate.atTime(14,15);//The first parameter is for Hour and other one is for minute.

您可以在此处找到更多详细信息:Java Time LocalDateTime At Time Functions

© www.soinside.com 2019 - 2024. All rights reserved.