1.先新建一个html页面保存公共页面,并对公共片段设置片段id,并设置引入片段是进行判断高亮。
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!-- 引入侧边栏-->
<ul class="list-unstyled" th:fragment="sidebar">
<li class="active" th:class="${activeUrl=='books'?'active':''}"><a href="/books"> <i class="icon-home"></i>图书信息 </a></li>
<li th:class="${activeUrl=='readers'?'active':''}"><a href="/readers"> <i class="icon-grid"></i>读者信息 </a></li>
<li th:class="${activeUrl=='borrowInfo'?'active':''}"><a href="/borrow_info"> <i class="fa fa-bar-chart"></i>借阅记录 </a></li>
<li th:class="${activeUrl=='admin'?'active':''}"><a href="/admin"> <i class="icon-padnote"></i>个人信息 </a></li>
</ul>
</body>
</html>
2.html主页面进行页面引入的时候传入参数
<ul th:replace="commons/sidebar::sidebar(activeUrl='books')">