首页 > 其他分享 >webFlux routers 嵌套路由解析规则

webFlux routers 嵌套路由解析规则

时间:2023-01-19 02:44:13浏览次数:67  
标签:嵌套 routers webFlux accept APPLICATION JSON handler b1 id

有下列路由

 public RouterFunction<ServerResponse> doctorRoutes(DoctorHandler handler) {
        return RouterFunctions.route()
                .path("/doctors",b1 -> b1
                        .POST( handler::save)
                        .POST("/patient/{id}", accept(MediaType.APPLICATION_JSON), handler::addPatient)
                        .GET("/patients/{d_id}",accept(MediaType.APPLICATION_JSON),handler::getPatientsByDoctorId)
                    )
                .build();

当请求/doctors/patient/153时,没有正确进入addPatient方法,而是进入/doctors下的save方法。解决方法:

 public RouterFunction<ServerResponse> doctorRoutes(DoctorHandler handler) {
        return RouterFunctions.route()
                .path("/doctors",b1 -> b1
                        .POST("/patient/{id}", accept(MediaType.APPLICATION_JSON), handler::addPatient)
                        .GET("/patients/{d_id}",accept(MediaType.APPLICATION_JSON),handler::getPatientsByDoctorId)
                         .POST( handler::save)
                    )
                .build();


来自为知笔记(Wiz)

标签:嵌套,routers,webFlux,accept,APPLICATION,JSON,handler,b1,id
From: https://www.cnblogs.com/baiyifengyun/p/17060985.html

相关文章