【发布时间】:2021-04-21 10:34:46
【问题描述】:
我在 Ktor 中有许多相同资源的 URI。为了避免重复太多行,我找到了这个解决方案:
routing {
get("/", home())
get("/index", home())
get("/home", home())
...
}
private fun home(): suspend PipelineContext<Unit, ApplicationCall>.(Unit) -> Unit =
{
val parameters = ...
call.respond(ThymeleafContent("/index.html", parameters))
}
有没有像这样更优雅的解决方案:
routing {
get("/", "/index", "/home") {
val parameters = ...
call.respond(ThymeleafContent("/index.html", parameters))
}
...
}
【问题讨论】: