无法在jhipster中获取基于datefield = currentdate的记录

时间:2019-02-06 10:38:24

标签: mysql rest spring-boot jpa jhipster

我一直在从事jhipster的项目。截至目前,我正努力与rest api来获取currentdate表(约会)的记录。该代码没有错误,但不输出任何东西。(我的表中也有数据)。

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

1 个答案:

答案 0 :(得分:2)

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