springboot webflux webclient 使用示例


springboot webflux webclient 使用示例

 

 

************************

示例

 

HelloController

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public Map hello(ServerWebExchange exchange){
        exchange.getRequest().getHeaders().forEach((key,value) ->{
            System.out.println(key+" ==> "+value);
        });

        Map map=new HashMap<>();
        map.put("info","hello world");

        return map;
    }

    @RequestMapping("/hello2/{name}")
    public String hello2(@PathVariable("name") String name){
        return "hello "+name;
    }

    @RequestMapping("/hello3")
    public String hello3(String name){
        return "hello "+name;
    }

    @RequestMapping("/hello4")
    public Person hello4(String name,Integer age){
        Person person=new Person();
        person.setName(name);
        person.setAge(age);

        System.out.println(name+"  "+age);
        return person;
    }

    @RequestMapping("/hello5")
    public Mono hello5(ServerWebExchange exchange){
        return exchange.getFormData().flatMap(map -> {
            Person person=new Person();
            person.setName(map.getFirst("name"));
            person.setAge(Integer.parseInt(Objects.requireNonNull(ma

你可能感兴趣的:(webflux)