普通写法
@GetMapping("/person/{id}")Mono<Person> findById(@PathVariable String id) {return this.repository.findOne(id);}
函数式写法-方法
public Mono<ServerResponse> getPerson(ServerRequest request) { int personId = Integer.valueOf(request.pathVariable("id"));Mono<ServerResponse> notFound = ServerResponse.notFound().build();Mono<Person> personMono = this.repository.getPerson(personId);return personMono.then(person -> ServerResponse.ok().contentType(APPLICATION_JSON).body(fromObject(person))).otherwiseIfEmpty(notFound);}
函数式写法-绑定路由
RouterFunction<ServerResponse> personRoute =route(GET("/person/{id}").and(accept(APPLICATION_JSON)), handler::getPerson)