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

Unable to fetch records based on datefield=currentdate in jhipster

我一直在用 jhipster 做一个项目。截至目前,我正在努力休息 api 以获取当前日期的 table(约会)的记录。代码没有错误,但没有输出任何东西。(我的 table 中也有数据)。

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

 @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());
}`