我一直在从事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());
}`
答案 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());
}`