玩一玩ktor

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32768743/article/details/84578774

看到gradle 5.0 发布,折腾 一下。
安装ktor插件,然后创建ktor工程。
在这里插入图片描述
在这里插入图片描述
然后跑起来

2018-11-28 09:14:59.234 [main] TRACE Application - {
    # application.conf @ file:/D:/src/demo-for-ktor/out/production/resources/application.conf: 6
    "application" : {
        # application.conf @ file:/D:/src/demo-for-ktor/out/production/resources/application.conf: 7
        "modules" : [
            # application.conf @ file:/D:/src/demo-for-ktor/out/production/resources/application.conf: 7
            "com.example.ApplicationKt.module"
        ]
    },
    # application.conf @ file:/D:/src/demo-for-ktor/out/production/resources/application.conf: 2
    "deployment" : {
        # application.conf @ file:/D:/src/demo-for-ktor/out/production/resources/application.conf: 3
        "port" : 8080
    },
    # Content hidden
    "security" : "***"
}

2018-11-28 09:15:00.842 [main] INFO  Application - No ktor.deployment.watch patterns specified, automatic reload is not active
2018-11-28 09:15:01.986 [main] INFO  Application - Responding at http://0.0.0.0:8080
2018-11-28 09:15:01.987 [main] INFO  Application - Application started: io.ktor.application.Application@1b410b60

看到这里,也没什么特别的。启动比Spring Boot要快。
创建的工程里给的代码很简单。

fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)

@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
    install(CallLogging) {
        level = Level.INFO
        filter { call -> call.request.path().startsWith("/") }
    }

    routing {
        get("/") {
            call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain)
        }
    }
}

  • 我想要是路由稍微多点,怎么写,难道都写一个routing里?
  • http参数怎么拿?
  • cookie和session等怎么用?
  • 事务怎么做
  • 和MyBatis怎么结合?难道DAO层也用JetBrains那个?

算了,不想了,又没看完文档,想也白想。其实我比较关注,这个东西是不是性能上会有很大提升,毕竟直接上了netty。

猜你喜欢

转载自blog.csdn.net/qq_32768743/article/details/84578774