900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 如何使用 Eclipse + Kotlin + tomcat 开发 Dynamic Web Server

如何使用 Eclipse + Kotlin + tomcat 开发 Dynamic Web Server

时间:2021-01-15 20:32:21

相关推荐

如何使用 Eclipse + Kotlin + tomcat 开发 Dynamic Web Server

如何使用 Eclipse + Kotlin + tomcat 开发 Dynamic Web Server ?

Eclipse 安装 Kotlin 插件后是无法开发 Dynamic Web Server 的, 除非再新建一个 Kotlin 项目, 然后将 bin 目录添加到 tomcat 的 CLASSPATH 中

要想完全使用 Kotlin 开发难度是很大滴, 不过, 如果你不在意的话, 是可以以 Java 注解 + Kotlin 的方式完成的

也就是说, Dispatcher 是无法扫描 Kotlin 类的, 所有 URL 请求都需要 Java 代理转发到 Kotlin

配置 tomcat

添加 Kotlin 运行库

添加 sping 库, Kotlin 项目

package controller;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import cont.ex.LoginCont;@Controllerpublic class IndexCont {static {System.out.println(IndexCont.class.getName() + " 类被初始化.");}@RequestMapping("index")public String index(Model m) {m.addAttribute("info", panion.getString("欢迎信息"));return new LoginCont().login(m);}}

package testclass JustFun {companion object {fun getString(param: String) : String {when(param) {"欢迎信息" -> return "Welcome to develon's house"}return "Haven't soutou suru data"}}}

访问/index.html

注意: Kotlin 项目修改后都需要运行一下才会被编译

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。