1.定义 macro片段,传参,其他页面引入标签
<#macro header title>
<head > <!--title为传参-->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title > </title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
<link rel="stylesheet" href="/css/typo.css" >
<link rel="stylesheet" href="/css/animate.css" >
<link rel="stylesheet" href="/lib/prism/prism.css" >
<link rel="stylesheet" href="/lib/tocbot/tocbot.css" >
<link rel="stylesheet" href="/css/me.css" >
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css">
<script src="https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/autoload.js"></script>
</head>
</#macro>
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<#-- header begin -->
<#-- header end -->
<#import "./common/header.html" as head>
<@head.header title="博客首页" />
2.定义 function,封装函数
例子:
<#function addClass bl>
<#return (bl)?string('active','')>
</#function>
<#macro nav page>
<!--头部导航-->
<nav class="ui attached segment m-padded-tb-mini m-shadow-small" >
<div class="ui container">
<div class="ui secondary stackable menu">
<h1 class="ui pink header item">Sakura</h1>
<a href="/a/" class="m-item item blue m-mobile-hide ${addClass(page==1)}" ><i class=" home icon"></i>首页</a>
<a href="/" class="m-item violet item m-mobile-hide ${addClass(page==1)}"><i class=" idea icon"></i>分类</a>
<a href="/" class="m-item pink item m-mobile-hide" ><i class=" tags icon"></i>标签</a>
<a href="/" class="m-item orange item m-mobile-hide" ><i class=" clone icon"></i>时间线</a>
<a href="/" class="m-item green item m-mobile-hide" ><i class=" info icon"></i>关于我</a>
<div class="right m-item item m-mobile-hide">
<form name="search" action="#" method="post" th:action="@{/search}" target="_blank">
<div class="ui icon transparent input m-margin-tb-tiny">
<input type="text" name="query" placeholder="Search...." th:value="${query}">
<i onclick="document.forms['search'].submit()" class="search link icon"></i>
</div>
</form>
</div>
</div>
</div>
<a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
<i class="sidebar icon"></i>
</a>
</nav>
<!--导航-->
</#macro>
获取basepath
${springMacroRequestContext.getContextPath()}