我一直在 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/