Mysql 无法根据jhipster中的datefield=currentdate获取记录
我一直在jhipster做一个项目。到目前为止,我正在努力使用RESTAPI获取currentdate表(约会)的记录。代码没有错误,但没有输出任何内容(我的表中也有数据) `获取/约会支出:获取所有状态为挂起的约会Mysql 无法根据jhipster中的datefield=currentdate获取记录,mysql,rest,spring-boot,jpa,jhipster,Mysql,Rest,Spring Boot,Jpa,Jhipster,我一直在jhipster做一个项目。到目前为止,我正在努力使用RESTAPI获取currentdate表(约会)的记录。代码没有错误,但没有输出任何内容(我的表中也有数据) `获取/约会支出:获取所有状态为挂起的约会 @param filter the filter of the request @return the ResponseEntity with status 200 (OK) and the list of appointments in body / @GetMapping
@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());
}`
@param筛选请求的筛选器
@返回状态为200(OK)的ResponseEntity和正文中的约会列表
/
@GetMapping(“/searchappointment”)
@定时
公共列表GetAllAppointOfToday(@RequestParam(required=false)字符串筛选器){
//LocalDate LocalDate=LocalDate.now();
//System.out.println(“localDate”);
log.debug(“获取所有状态为挂起的约会的REST请求”);
//LocalDate日期='2019-02-06'
返回流支持
.stream(appointmentRepository.findAll().spliterator(),false)
.filter(约会->约会.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());
}`
@GetMapping(“/searchappointment”)
@定时
公共列表GetAllAppointOfToday(@RequestParam(required=false)字符串筛选器){
//LocalDate LocalDate=LocalDate.now();
//System.out.println(“localDate”);
log.debug(“获取所有状态为挂起的约会的REST请求”);
//LocalDate日期='2019-02-06'
返回流支持
.stream(appointmentRepository.findAll().spliterator(),false)
.filter(约会->约会.getLastvisited().equals(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());
}`
@GetMapping(“/searchappointment”)
@定时
公共列表GetAllAppointOfToday(@RequestParam(required=false)字符串筛选器){
//LocalDate LocalDate=LocalDate.now();
//System.out.println(“localDate”);
log.debug(“获取所有状态为挂起的约会的REST请求”);
//LocalDate日期='2019-02-06'
返回流支持
.stream(appointmentRepository.findAll().spliterator(),false)
.filter(约会->约会.getLastvisited().equals(LocalDate.now()))
.collect(Collectors.toList());
}`