Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 函数之间的Spring boot JPA规范执行器_Spring Boot_Jpa_Spring Data Jpa - Fatal编程技术网

Spring boot 函数之间的Spring boot JPA规范执行器

Spring boot 函数之间的Spring boot JPA规范执行器,spring-boot,jpa,spring-data-jpa,Spring Boot,Jpa,Spring Data Jpa,我正在尝试比较数据库中两天之间的日期。我试着把它当作 ZonedDateTime startBottomTime = ZonedDateTime.of(2020, 9, 10, 15, 55, 33, 0, ZoneOffset.UTC); ZonedDateTime startTopTime = ZonedDateTime.of(2020, 9, 13, 15, 55, 35, 0, ZoneOffset.UTC); predicates.add(criteriaBuilder.greate

我正在尝试比较数据库中两天之间的日期。我试着把它当作

ZonedDateTime startBottomTime = ZonedDateTime.of(2020, 9, 10, 15, 55, 33, 0, ZoneOffset.UTC);
ZonedDateTime startTopTime = ZonedDateTime.of(2020, 9, 13, 15, 55, 35, 0, ZoneOffset.UTC);

predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("createdDatetime"), startBottomTime));
predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("createdDatetime"), startTopTime));
这将返回0个结果。但是我执行了下面的查询,效果很好,并给出了预期的结果

SELECT * from file_data fd where fd.created_date_time between '2020-09-10 15:55:33' AND '2020-09-13 15:55:35'

如何修复此问题?

我将使用java.util.Date和java.util.Calendar尝试以下操作:

Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, 2020);
c.set(Calendar.MONTH, 8);
c.set(Calendar.DAY_OF_MONTH, 10);
[...]

Date startDate = c.getTime();

c.set(Calendar.DAY_OF_MONTH, 13);
[...]

Date endDate = c.getTime();

//between is not the same as greater than equal and less than or equal, exclude the limits
predicates.add(cb.between(root.get("createdDatetime"), startDate, endDate));