springboot webflux 参数传递(url路径传递)
url传递的参数可使用注解(@PathVariable)读取,也可通过路由函数读取
***********************
注解:@PathVariable
@RestController
public class HelloController {
@RequestMapping("/get/{name}")
public String hello(@PathVariable("name") String name){
System.out.println("name:"+name);
return name;
}
}
***********************
路由函数
@Configuration
public class CustomRouterConfig {
@Bean
public RouterFunction<ServerResponse> initRouterFunction(){
return RouterFunctions.route()
.GET("/hello/{name}",serverRequest -> {
String name=serverRequest.pathVariable("name");
System.out.println("name:"+name);
return ServerResponse.ok().bodyValue(name);
})
.build();
}
}