我从数据库中获取Flux<Employee>
,我想将其转换为Mono<EmployeeRespnose>
,其中将包含员工列表。
public Mono<EmployeeResponse> getEmployeeResponse(){
Flux<Employee> employeeFlux = repository
.findEmployees();
return //How to begin here??;
}
我不知道如何开始。(操作应该是非阻塞的)
请提供任何提示 / 建议,我怎么能开始呢?
//class Employee
class Employee{
private Long ID;
private String name;
private String address;
//getters and setters
}
//EmployeeResponse class
class EmployeeResponse{
private int count;
private List<Employee> list;
//getters and setters
}
我使用employeeFlux.collectList()
获取Mono<List<Employee>>
,然后使用map()
将List<Employee>
转换为Mono<EmployeeResponse>
public Mono<EmployeeResponse> getEmployeeResponse(){
Flux<Employee> employeeFlux = Flux.empty() ;
return employeeFlux.collectList().map(emplist -> {
EmployeeResponse response = new EmployeeResponse();
response.setCount(emplist.size());
response.setList(emplist);
return response;
});
}
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(15条)