我在 springboot 应用程序中有以下控制器,我用来根据给定的员工 ID 获取员工。@GetMapping(path = "employee/{empId}", produces = "application/json; charset=UTF-8")public Mono<ResponseEntity<Object>> getEmployee(@PathVariable(name = "empId") String empID, @RequestParam(name = "showExtraDetails", defaultValue = "false") boolean showExtraDetails) { Mono<Employee> employeeFound = employeeService.getEmployee(empID, showExtraDetails); if (employeeFound != null) { return Mono.just(new ResponseEntity<>(employeeFound, HttpStatus.OK)); } }我可以在邮递员中看到状态代码 200,但我看不到作为响应正文的员工详细信息。相反,我看到以下内容:{"scanAvailable": true} 有没有办法在不阻塞流的情况下显示员工属性?
1 回答
慕村9548890
TA贡献1884条经验 获得超4个赞
我不知道,但它可能有把做Mono<Employee>的ResponseEntity直接。这应该有效:
return employeeService.getEmployee(empID, showExtraDetails)
.map(employee-> new ResponseEntity<>(employee, HttpStatus.OK))
.defaultIfEmpty(new ResponseEntity<>(HttpStatus.NOT_FOUND));
添加回答
举报
0/150
提交
取消