kotlin - 我如何重新定向另一条路径
问题描述
我有这段代码,我想在 id == 1 时转发到另一条路径
get("/courses/{id}"){
val id = call.parameters["id"]?.toInt()
if (id is Int) {
if (id == 1)
// i want redirection to "/courses/top"
}
}
解决方案
您可以使用call.respondRedirect
:
if (call.parameters["id"]?.toIntOrNull() == 1) {
call.respondRedirect("/courses/top")
}
推荐阅读
- javascript - Javascript没有像预期的那样迭代
- django - 使用 datetime-local 在 Django 中的 DateTimeField() 中插入数据
- java - ProGet Maven 存储库提要 API 访问
- printjs - 使用 printJS 打印 Google 字体
- python - 将具有多列数据的同一列行数据转换为新数据框
- c - C代码如何使用资源文件夹将声音添加到.exe?
- asp.net - 如何使用 .NET MVC 使用 Microsoft Graph 检索经理下的成员?
- sms - 如何从 Twilio 可编程 SMS API 读取收到的 SMS 消息
- python - 如何将 Tkinter Text 小部件中的选定文本放在前面?
- angular - Angular 4,多个api调用并等待结果