引入mavin
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
yml配置
thymeleaf: cache: false # 方便前端可以及时拿到更新数据 check-template-location: true prefix: classpath:/templates/ suffix: .html encoding: utf-8 mode: HTML5
如果通过拦截器访问thymeleaf丢失样式、脚本
<link rel="icon" href="../assets/img/favicon.ico" th:href="@{~../assets/img/favicon.ico}"> <link rel="stylesheet" type="text/css" href="css/webbase.css" th:href="@{~/css/webbase.css}" /> <link rel="stylesheet" type="text/css" href="css/pages-login-manage.css" th:href="@{~/css/pages-login-manage.css}" />
使用th:href在路径前面加一个~即可解决