springboot整合thymeleaf始终无法显示页面,求高人支招。
pom.xml配置
<?xml version="1.0" encoding="UTF-8"?> <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> <groupId>com.ran.learn</groupId>
<artifactId>demo</artifactId> <!-- <version>0.0.1-SNAPSHOT</version> -->
<packaging>war</packaging> <name>demo</name> <description>Demo project for
Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE
</version> <relativePath/> <!-- lookup parent from repository --> </parent>
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version> <main.basedir>${basedir}/../..</main.basedir>
</properties> <dependencies> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId> </dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <scope>test</scope>
</dependency> <!-- springframework web包 --> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional> </dependency> <dependency> <!-- 引入freeMarker的依赖包.
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId> --> <!--
引入thymeleaf的依赖包 --> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
</dependencies> <build> <plugins> <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
</project>
Handler类
@Controller @RequestMapping(value="/users") public class UserController {
@RequestMapping(value="/page/all") public String userListPage() { return
"test"; } }
工程结构
test.html内容
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta
http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Insert
title here</title> </head> <body> 这里是templates的的的 </body> </html>
访问地址:
http://localhost:8080/users/page/all
结果:
程序可以正常导出debug到controller方法里,但是无法显示test.html,始终显示如下:
我上边用的springboot版本是:
2.0.1.RELEASE
如果我换成1.5版本的springboot就可以正常运行,不知道为什么,求高人指点!谢谢,谢谢,两天了,没找到原理,网上,各种方法都试了。基本用的都是1.5左右的springboot,我说的是2.0.1的版本,怎样做,才能正常运行。
热门工具 换一换