gpt4 book ai didi

java - Kotlin+spring+mustache @Controller 不工作(Whitelabel 错误页面)但 @RestController 工作

转载 作者:行者123 更新时间:2023-12-01 16:45:37 25 4
gpt4 key购买 nike

Kotlin 上的 spring 有一些问题。当我设置 @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

@Controller
class SomeController {

@GetMapping("/")
fun index(model: Model): String {
model["something"] = "asd"

return "index"
}
}

索引. mustache :

<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>

提前致谢

最佳答案

您没有在 pom.xml 中添加模板引擎添加以下内容:

<dependency>          
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mustache</artifactId>
</dependency>

关于java - Kotlin+spring+mustache @Controller 不工作(Whitelabel 错误页面)但 @RestController 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61784749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com