集成HTML和CSS与Kotlin和Spring MVC

我想为我的spring项目添加一些html和css。 我正在运行gradle,并使用Kotlin。 我目前的树目录是这样的: 链接 (我没有包括gradle构建文件)。

我只是试图打印“Hello $ name $”给一些输入的网址。 这工作。 这里是GreetingController.kt:

@RestController class GreetingController { @RequestMapping("/greeting") fun greeting(@RequestParam(value = "name", defaultValue = "World") name: String, model: Model) { model.addAttribute("name", name); return "greeting"; } } 

我的gradle.build文件:

 buildscript { ext.kotlin_version = '1.1.2' // Required for Kotlin integration ext.spring_boot_version = '1.5.3.RELEASE' repositories { jcenter() mavenCentral() } dependencies { classpath "se.transmode.gradle:gradle-docker:1.2" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // Required for Kotlin integration classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version" } } apply plugin: 'docker' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'kotlin' // Required for Kotlin integration apply plugin: 'org.springframework.boot' apply plugin: 'application' jar { baseName = 'webapp' version = '0.1.0' } repositories { jcenter() } dependencies { compile "org.springframework.boot:spring-boot-starter-thymeleaf" compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // Required for Kotlin integration compile 'org.springframework.boot:spring-boot-starter-web' testCompile 'junit:junit' } task buildDocker(type: Docker, dependsOn: build) { push = false applicationName = jar.baseName dockerfile = file('src/main/docker/Dockerfile') doFirst { copy { from jar into stageDir } } } task wrapper(type: Wrapper) { gradleVersion = '3.5' } springBoot { mainClass = 'com.tunnll.spring.webapp.Application' } 

另外,我的html文件:

 <!DOCTYPE HTML> <html xmlns:th="http://www.thymeleaf.org"> <head> <title>Getting Started: Serving Web Content</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <p th:text="'Hello, ' + ${name} + '!'" /> </body> </html> 

编辑:网站在本地运行,所以我不能提供一个链接。 目前,它在GreetingController中打印出我正在返回的“问候语”。 不过,我希望它显示为“Hello World”,这是由html文件产生的。 这可能是一个HTML文件没有连接到应用程序的问题。 我不确定。 任何帮助,将不胜感激。

问题是,当我只使用@Controller时,我正在使用@RestController。 另外,html文件应该位于resources / templates目录下。