我正在关注此guide,但“ TheApp”部分以红色突出显示,并且我得到一个空白网页作为输出。我需要导入一些库以使其得到认可吗?
如果我没有将任何数据传递到模板中,是否可以将'model'保留为空白字符串?
我的Kotlin代码:
import io.ktor.server.netty.*
import io.ktor.routing.*
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.server.engine.*
import freemarker.cache.*
import io.ktor.freemarker.*
import io.ktor.freemarker.FreeMarkerContent
fun main(args: Array<String>) {
embeddedServer(Netty, 3000) {
install(FreeMarker) {
templateLoader = ClassTemplateLoader(TheApp::class.java.classLoader, "templates")
}
routing {
get("/") {
call.respond(FreeMarkerContent("templ.ftl", "", "e"))
}
}
}.start(wait = true) }
渐变部分:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.21'
}
group 'rest-group'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
ext.ktor_version = '1.1.3'
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testCompile group: 'junit', name: 'junit', version: '4.12'
compile "io.ktor:ktor:$ktor_version"
compile "io.ktor:ktor-gson:$ktor_version"
compile "io.ktor:ktor-freemarker:$ktor_version"
compile "io.ktor:ktor-html-builder:$ktor_version"
compile "io.ktor:ktor-server-netty:$ktor_version"
compile "io.ktor:ktor-auth:$ktor_version"
compile "io.ktor:ktor:$ktor_version"
compile "ch.qos.logback:logback-classic:1.2.3"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
答案 0 :(得分:0)
“ TheApp”需要替换为“ this”。 'this'选择正在为ktor运行的应用程序的实例。
“模型”必须是mapOf引用类型,即使未使用值也是如此。