是否可以将多个参数传递给 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
,并且响应 stauts 代码是 404。我真的需要传递更多参数(从一到三或四个)...
最佳答案
这非常适合 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")
}
关于rust - 如何将许多参数传递给 rust actix_web 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59772857/