java Kotlin+spring+mustache@Controller不工作(白标签错误页面),但@RestController工作
科特林的弹簧有问题。当我设置@RestController并转到localhost:8080时,我可以看到“index”。如果我设置@Controller,我有
Whitelabel Error Page
This application has no configured error view, so you are seeing this as a fallback.
Wed May 13 23:34:59 EEST 2020
There was an unexpected error (type=Not Found, status=404).
我不知道它为什么不起作用。在java中,类似的代码(来自教程)正在运行。我的代码基于java教程中的代码。 我的应用。kt
@SpringBootApplication
class Application
fun main(args: Array<String>) {
runApplication<Application>(*args)
}
某个控制器
@Controller
class SomeController {
@GetMapping("/")
fun index(model: Model): String {
model["something"] = "asd"
return "index"
}
}
索引。胡子:
<html>
<body>
<div>
its the {{something}}
</div>
</body>
</html>
还有pom。xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
提前谢谢
# 1 楼答案
您的pom中没有添加模板引擎。xml添加以下内容: