【问题标题】:How to use the Kotlinx.html in Spring in place of the normal html template engine for JSP or Thymeleaf?如何在 Spring 中使用 Kotlinx.html 代替 JSP 或 Thymeleaf 的普通 html 模板引擎?
【发布时间】:2019-03-05 16:07:08
【问题描述】:

传统 html 模板引擎的缺陷是缺少类型安全和编译时检查。有大佬建议Kotlinx.html可以极大地弥补传统html模板引擎的缺陷。

所以我打算在 Java 中使用 Spring 而没有 html 模板引擎,比如没有 SpringResourceTemplateResolverSpringTemplateEngine,而是用 kotlin 代码注入em>kotlinx.html。但目前我已经完全知道如何进行

【问题讨论】:

    标签: spring-mvc kotlin java-8 kotlinx-html


    【解决方案1】:

    现在我只是返回一个带有 kotlin html dsl 作为返回语句和控制器方法上的 @ResponseBody 注释的字符串。

    @Controller
    @RequestMapping("/")
    class MyController constructor(){
    
      @GetMapping
      @ResponseBody
      fun index(): String {
    
        return myKotlinHtmlView()
      }
    }
    

    其中myKotlinHtmlView()是模板所在的函数

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-26
      • 1970-01-01
      • 2020-08-27
      • 2018-02-06
      • 1970-01-01
      • 2018-12-08
      • 1970-01-01
      • 2014-07-06
      相关资源
      最近更新 更多