1.定义一个公共页面导航栏

<!--头部导航栏-->
<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0" th:fragment="topbar">
    <a class="navbar-brand col-sm-3 col-md-2 mr-0" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#" th:text="${session.loginUser}"></a>
    <input class="form-control form-control-dark w-100" type="text" placeholder="Search" aria-label="Search">
    <ul class="navbar-nav px-3">
        <li class="nav-item text-nowrap">
            <a class="nav-link" th:href="@{/user/logout}">注销</a>
        </li>
    </ul>
</nav>

2.在使用的地方引入即可

<!--顶部导航栏-->
        <div th:replace="~{common/commons::topbar}"></div>

3.thymeleaf传参数:URL表达式推荐写法,简单好看,可读性高。(如果是多个参数用,分隔)

<div th:replace="~{common/commons::sidebar(active='main.html')}"></div>

4.使用

 <a th:class="${active=='main.html'?'nav-link active':'nav-link'}" th:href="@{/index.html}">

thymeleaf:文档

Tutorial: Using Thymeleaf

posted on 2022-01-07 16:58  upupup-999  阅读(408)  评论(0)    收藏  举报