【问题标题】:Unable to fetch records based on datefield=currentdate in jhipster无法根据日期字段获取记录 = jhipster 中的当前日期
【发布时间】:2019-06-30 06:50:40
【问题描述】:

我一直在做 jhipster 的一个项目。到目前为止,我正在努力使用休息 api 来获取当前日期的表(约会)的记录。该代码没有错误但没有输出任何内容。(我的表中也有数据)。

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

【问题讨论】:

    标签: mysql rest spring-boot jpa jhipster


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多