webflux 对url参数的接收处理

普通写法

@GetMapping("/person/{id}")
	Mono findById(@PathVariable String id) {
		return this.repository.findOne(id);
	}

函数式写法-方法

public Mono getPerson(ServerRequest request) { 
		int personId = Integer.valueOf(request.pathVariable("id"));
		Mono notFound = ServerResponse.notFound().build();
		Mono personMono = this.repository.getPerson(personId);
		return personMono
				.then(person -> ServerResponse.ok().contentType(APPLICATION_JSON).body(fromObject(person)))
				.otherwiseIfEmpty(notFound);
	}

函数式写法-绑定路由

RouterFunction personRoute =
	route(GET("/person/{id}").and(accept(APPLICATION_JSON)), handler::getPerson)

 

你可能感兴趣的:(java,spring,cloud,Spring,Cloud,webflux)