mysql - 无法根据 jhipster 中的日期字段=当前日期获取记录

标签 mysql rest spring-boot jpa jhipster

我一直在 jhipster 中从事一个项目。截至目前,我正在努力使用 REST API 来获取当前日期的表(约会)的记录。代码没有错误,但不输出任何内容。(我的表中也有数据)。

`GET/appointmentspending :获取所有状态为待处理的约会。

 @param filter the filter of the request
 @return the ResponseEntity with status 200 (OK) and the list of appointments in body
 /
@GetMapping("/searchappointment")
@Timed
public List<Appointment> getAllAppointmentOfToday(@RequestParam(required = false) String filter) {
     //LocalDate localDate = LocalDate.now();
    // System.out.println("localDate");
  log.debug("REST request to get all Appointments with status pending");
          //LocalDate date = '2019-02-06'

    return StreamSupport
            .stream(appointmentRepository.findAll().spliterator(), false)
            .filter(appointment -> appointment.getLastvisited() == LocalDate.now())
            .collect(Collectors.toList());
}`

最佳答案

在 Java 中,您不能使用 == 来比较对象,因为它比较的是对象引用,而不是对象的实际值。这类似于 C 和 C++ 中比较两个指针。

为了比较它们的值,请使用对象的 equals 方法。

所以你的代码现在看起来如下:

@GetMapping("/searchappointment")
@Timed
public List<Appointment> getAllAppointmentOfToday(@RequestParam(required = false) String filter) {
    // LocalDate localDate = LocalDate.now();
    // System.out.println("localDate");
    log.debug("REST request to get all Appointments with status pending");
    // LocalDate date = '2019-02-06'

    return StreamSupport
            .stream(appointmentRepository.findAll().spliterator(), false)
            .filter(appointment -> appointment.getLastvisited().equals(LocalDate.now()))
            .collect(Collectors.toList());
}`

关于mysql - 无法根据 jhipster 中的日期字段=当前日期获取记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54551575/

相关文章:

java - 尝试使用 java spring boot、hibernate 和 thymeleaf 坚持 MAP,但在验证时遇到错误

spring - 配置 spring boot 将 404 重定向到单页应用

mysql - 清理多个编号的 mysql 表

php - 我们如何将动态创建的文本框值获取到另一个 php 文件

javascript - Angular $resource 从 REST 查询字符串中删除问号

java - 如何通知客户端有关 Rest 端点更改的信息

java - Spring Boot 中的 Multi-Tenancy

MYSQL 数据库查询与连接和计数

mysql - SQL返回每组单行

java - 如何组织Spring项目