webflux中有下列路由:
public RouterFunction<ServerResponse> doctorRoutes(DoctorHandler handler) {
return RouterFunctions.route()
.path("/doctors",b1 -> b1
.nest(accept(MediaType.APPLICATION_JSON), b2 -> b2
.GET("/{id}", handler::getDoctorById)
.GET("/info", handler::responseUserInfo)
)
.POST( handler::save)
)
.build();
}
路径/doctors/{id}与/doctors/info发生了冲突,当请求/doctors/info时发生报错,如把其中一个去掉后剩余一个时能正常请求。始终不明白是怎么回事,在我的理解中当请求info时应该走的是/doctors/info,但是走的是/doctors/{id}这个路径。突然想起这是一个嵌套路由,在paht方法中共享前缀。随即修改为:
public RouterFunction<ServerResponse> doctorRoutes(DoctorHandler handler) {
return RouterFunctions.route()
.GET("/doctors/info", accept(MediaType.APPLICATION_JSON), handler::responseUserInfo)
.path("/doctors",b1 -> b1
.nest(accept(MediaType.APPLICATION_JSON), b2 -> b2
.GET("/{id}", handler::getDoctorById)
)
.POST( handler::save)
)
.build();
}
冲突解决,都能正常访问。有大神知道什么原理请留言,不胜感激!