springboot webflux 使用示例(注解)
webflux 可使用类似于spring mvc的注解(@RequestMapping、@RequestParam、@PathVariable等)进行数据处理
**************************
示例
*******************
controller 层
HelloController
@RestController
public class HelloController {
@RequestMapping("/get/{name}")
public String hello(@PathVariable("name") String name){
System.out.println("name:"+name);
return name;
}
@RequestMapping("/get2")
public String hello2(@RequestParam String name){
System.out.println("name:"+name);
return name;
}
@RequestMapping("/get3")
public String hello3(ServerWebExchange exchange){
String name=exchange.getRequest().getQueryParams().getFirst("name");
System.out.println("name:"+name);
return name;
}
@RequestMapping("/get4")
public Mono<String> hello4(ServerHttpRequest request){
String name=request.getQueryParams().getFirst("name");
System.out.println("name:"+name);
assert name != null;
return Mono.just(name);
}
}
**************************
使用测试
localhost:8080/get/hello
localhost:8080/get2?name=瓜田李下
localhost:8080/get3?name=瓜田李下
localhost:8080/get4?name=瓜田李下