前后端分离的情形下thymeleaf的正确使用方式
**不使用thymeleaf的任何模板语法、只是用thymeleaf做静态资源的映射和转发**
注意:
1、 thymeleaf静态资源映射的时候、假设静态资源目录为static
(静态资源目录默认为 rescouse\public\static\..)
以引入css文件为例:th:href="@{css/index.css}"
以上写法是错误的!!
正确写法应为 th:href="@{/css/index.css}"
css 前面的 / 不能省略!!
2、/ 代表是相对于服务器虚拟目录的路径
而不加 / 是相对于浏览器当前url的路径!
不注意这一点、公共页面静态资源整合引入时会出现问题!!
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:fragment="head">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title >Vivi的博客后台</title>
<link rel="stylesheet" th:href="@{/layui/css/layui.css}">
<link rel="stylesheet" th:href="@{/css/index.css}">