可以将多个参数传递到axtic_web路由吗?
// srv.rs (frag.)
HttpServer::new(|| {
App::new()
.route(
"/api/ext/{name}/set/config/{id}",
web::get().to(api::router::setExtConfig),
)
})
.start();// router.rs (frag.)
pub fn setExtConfig(
name: web::Path<String>,
id: web::Path<String>,
_req: HttpRequest,
) -> HttpResponse {
println!("{} {}", name, id);
HttpResponse::Ok()
.content_type("text/html")
.body("OK")
}对于只有一个参数的路由,一切正常,但在本例中,我在浏览器中只看到消息:wrong number of parameters: 2 expected 1,响应状态代码为404。
我真的需要传递更多的参数(从一个到三个或四个)……
发布于 2020-01-16 23:36:27
这非常适合tuple
pub fn setExtConfig(
param: web::Path<(String, String)>,
_req: HttpRequest,
) -> HttpResponse {
println!("{} {}", param.0, param.1);
HttpResponse::Ok().content_type("text/html").body("OK")
}https://stackoverflow.com/questions/59772857
复制相似问题