springboot webflux 参数传递(json传递)


springboot webflux 参数传递(json传递)

 

json传递的参数数据可用注解读取,也可用路由函数处理

 

 

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

注解:@RequestBody

 

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

controller 层

 

HelloController

@RestController
public class HelloController {

    @RequestMapping("/hello2")
    public String hello2(@RequestBody Person person){
        System.out.println(person);

        return person.toString();
    }

    @RequestMapping("/hello3")
    public Mono hello3(@RequestBody Mono person){
        return person.doOnNext(System.out::println);
    }

    @RequestMapping("/hello4")
    public Flux hello4(@RequestBody Flux person){
        return person.doOnNext(System.out::println);
    }
}

 

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

前端页面

 

hello.html




    
    Title
    
    


name:
age:

 

 

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

路由函数

 

CustomRouterConfig

@Configuration
public class CustomRouterConfig {

    @Bean
    public RouterFunction initRouterFunction(){
        return RouterFunctions.route()
                .POST("/hello3",serverRequest -> {
                    Mono person=serverRequest.bodyToMono(Person.class);

                    return ServerResponse.ok().body(person.doOnNext(System.out::println),Person.class);
                })
                .POST("/hello4",serverRequest -> {
                    Flux person=serverRequest.bodyToFlux(Person.class);

                    return ServerResponse.ok().body(person.doOnNext(System.out::println),Person.class);
                })
                .build();
    }
}

 

 

你可能感兴趣的:(webflux)