【问题标题】:how do I readirect t another path我如何重新定向另一条路径
【发布时间】:2019-12-17 22:51:00
【问题描述】:

我有这段代码,我想在 id == 1 时转发到另一条路径

get("/courses/{id}"){
    val id = call.parameters["id"]?.toInt()
    if (id is Int) {
        if (id == 1)
        // i want redirection to "/courses/top"
    }
}

【问题讨论】:

    标签: kotlin ktor


    【解决方案1】:

    你可以使用call.respondRedirect:

    if (call.parameters["id"]?.toIntOrNull() == 1) {
        call.respondRedirect("/courses/top")
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-09
      • 2018-12-18
      • 2020-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多