Spring boot(17) thymeleaf 使用类似于include的方式

1.建立模板

secure_template.html



<html xmlns:th="http://www.thymeleaf.org">
    <head>
        <title>权限centertitle>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" th:href="@{/mg/css/table.css}" />
        <link rel="stylesheet" type="text/css" th:href="@{/mg/css/public.css}" />
        <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js">script>
        <link href="//cdn.bootcss.com/bootstrap/3.0.1/css/bootstrap.min.css" rel="stylesheet"/>
        <script src="//cdn.bootcss.com/bootstrap/3.0.1/js/bootstrap.js">script>
    head>
    <body>
        <div id="wrapper">
        <nav class="navbar navbar-default navbar-inverse navbar-fixed-top" role="navigation">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigationspan><span class="icon-bar">span><span
                        class="icon-bar">span><span class="icon-bar">span>
                button>
                <a class="navbar-brand" href="#"><span class="glyphicon glyphicon-home">Homespan>a>
            div>
            <div class="collapse navbar-collapse"
                id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="/mg/sercure_roles">角色列表a>li>
                    <li><a href="/mg/sercure_accounts">用户列表a>li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">监控<strong class="caret">strong>a>
                        <ul class="dropdown-menu">
                            <li><a href="#">用户a>li>
                            <li><a href="#">角色a>li>
                            <li class="divider">li>
                            <li><a href="#">日志监控a>li>
                        ul>
                    li>
                ul>
            div>
        nav>
        <div style="margin-top: 5%" th:include="this :: content">div>
        <div id="footer">
            @ gaotianyue
        div>
        div>
    body>
html>

其中最重要的是th:include=”this :: content”

2使用方法


<html lang="zh-CN"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="secure_template">
<head>
<title>角色管理title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
head>
<link rel="stylesheet" type="text/css" th:href="@{/mg/css/table.css}" />
<link rel="stylesheet" type="text/css" th:href="@{/mg/css/public.css}" />
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js">script>
<link href="//cdn.bootcss.com/bootstrap/3.0.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="//cdn.bootcss.com/bootstrap/3.0.1/js/bootstrap.js">script>
    <body>
        <div th:fragment="content" >
            
            <div class="container"> 
            div>
        div>
    body>
html>

其中最重要的是 layout:decorator=”secure_template”
div th:fragment=”content”

你可能感兴趣的:(spring-boot,themeleaf)