webFlux routers 嵌套路由解析规则

有下列路由

 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)


posted on 2023-01-19 02:26  白衣风云  阅读(67)  评论(0编辑  收藏  举报

导航