首先html的网页
<!DOCTYPE html> //注意这个xmlns后面一定是https,我的就是没加s导致无法识别msg这种变量 <html lang="en" xmlns:th="https://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Thymeleaf 语法</title> </head> <body> <p th:text="${msg}"></p> </body> </html>
其次,html文件基本都说是放在templates文件夹下,然后用application.properties写一下解析器(前4行应该都必要写上去)
spring.resources.static-locations=classpath:/templates/
spring.thymeleaf.cache=false
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8
最重要的导入的包!!!!我可能这一天就死在导包上了
<properties> <java.version>1.8</java.version> <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version> <project.build.sorceEncoding>UTF-8</project.build.sorceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> //下面是我觉得必须要用到的包,反正我少一个就起不来,百度上的也没总结,我就自己写了 <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf-spring5</artifactId> <version>3.0.11.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>net.sourceforge.nekohtml</groupId> <artifactId>nekohtml</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf</artifactId> <version>3.0.9.RELEASE</version> </dependency>
当然web的包是必要的这边也再做下累述吧。嫌自己看包麻烦想复制粘贴配置的请复制下面的
<?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 https://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.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <java.version>1.8</java.version> <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version> <project.build.sorceEncoding>UTF-8</project.build.sorceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <groupId>com.joel.shiro</groupId>