thymeleaf各种问题,标签没用?网页404?
2019-08-29 09:02:23来源:博客园 阅读 ()
thymeleaf各种问题,标签没用?网页404?
首先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> <artifactId>01-demo-shiro</artifactId> <version>1.0.0</version> <name>01-demo-shiro</name> <description>Project for Spring Boot</description> <dependencies> <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-web</artifactId> </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-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>javax.servlet.jsp-api</artifactId> <version>2.3.1</version> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf</artifactId> <version>3.0.9.RELEASE</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>1.4.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> </includes> </resource> <resource> <directory>src/main/webapp</directory> <targetPath>META-INF/resources</targetPath> <includes> <include>**/*.*</include> </includes> </resource> </resources> </build> </project>
最后的话,controller层基本应该没什么问题的,后台传个值到前台。这里也不多做累述。
觉得此文章对你有帮助的话帮我点个赞吧= =!
原文链接:https://www.cnblogs.com/JoelKing/p/11420652.html
如有疑问请与原作者联系
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 面试的时候按照这个套路回答 Java GC 的相关问题一定能过 2020-06-08
- 我可真是醉了,一个SpringBoot居然问了我30个问题 2020-06-08
- Mybaties简单实例测试及注意问题 2020-06-07
- java对象指向问题 2020-06-07
- 解决IDEA Maven下载依赖包速度慢问题 2020-06-05
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash