[英]Query entity elements by createdAt on specific date range does not work
My entity has createdAt field which is filled by @CreatedDate
when the entity is created.我的实体有 createdAt 字段,该字段在创建实体时由
@CreatedDate
填充。 This property is of Date
type.该属性是
Date
类型。
class MyEntity {
@CreatedDate
private Date createdAt;
}
I would like to filter out all entities in a List
that are in a range from startDate to endDate.我想过滤掉
List
中从 startDate 到 endDate 范围内的所有实体。 The problem is that when I used findAllByCreatedAtBetween(Date startDate, Date endDate);
问题是当我使用
findAllByCreatedAtBetween(Date startDate, Date endDate);
it worked but not for all cases.它有效,但并非适用于所有情况。 When the entity is created ie: 2019-10-25 14:15:23 I would like to get it also when the user will type as
@RequestParam
startDate from 2019-10-24 00:00 endDate to 2019-10-25 14:15 and also take this entity.创建实体时,即:2019-10-25 14:15:23 当用户从 2019-10-24 00:00 endDate 到 2019-10-25 14 键入
@RequestParam
startDate 时,我也想得到它:15 也拿这个实体。 How could I ignore everything that is behind minutes?我怎么能忽略分钟后面的一切? Is there a way, because when I pass those values as startDate and endDate the entity isn't found, to find it I have to change 14:15 to 14:16.
有没有办法,因为当我将这些值作为 startDate 和 endDate 传递时,找不到实体,要找到它,我必须将 14:15 更改为 14:16。
You can set any parameter without others in LocalDateTime.您可以在 LocalDateTime 中设置没有其他参数的任何参数。 For example you want handle without minute.
例如,您想要处理没有分钟。 You can set your search date parameter like this:
您可以像这样设置搜索日期参数:
LocalDateTime localDateTime= myDate.atTime(14,15);//The first parameter is for Hour and other one is for minute.
You can find more detail here: Java Time LocalDateTime At Time Functions您可以在此处找到更多详细信息: Java Time LocalDateTime At Time Functions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.