【发布时间】:2019-10-10 11:44:36
【问题描述】:
我正在使用 thymeleaf 设置一个 Spring Boot 项目,但我的视图没有显示并且在浏览器中出现以下错误。
白标错误页面 此应用程序没有显式映射 /error,因此您将其视为后备。 2019 年 5 月 24 日星期五 00:44:22 GST 出现意外错误(类型=未找到,状态=404)。 没有可用的消息
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
控制器:
@Controller
public class MainController {
@GetMapping("/")
public String homePage() {
return "home";
}
}
application.properties:
spring.thymeleaf.cache=false
spring.thymeleaf.enabled=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.application.name=Bootstrap Spring Boot
我在我的 html 文件中添加了 thymeleaf 功能,但是当它不起作用时,我只是把它变成了简单的 html 文件。我的 home.html 是:
<html>
<head>
<title>Home Page</title>
</head>
<body>
<h1>Hello !</h1>
<p>
Welcome to Our App</span>
</p>
</body>
</html>
这是一个非常简单和基本的控制器。我在控制台中没有看到任何异常堆栈跟踪。
【问题讨论】:
-
做
return "index";。并且还要添加 并且还要添加<html xmlns:th="http://www.thymeleaf.org"> -
@want2learn,关于
"index"抱歉,这是拼写错误。我已经更新了这个问题。我已经添加了推荐的标签,但是没有用。
标签: spring spring-boot spring-mvc thymeleaf