thymeleaf th:insert th:replace th:include

thymeleaf th:insert th:replace th:include

1.抽取公共片段

抽取公共片段: th:fragment="片段名"

test.html
<test th:fragment="test">
    <p>thymeleafp>
test>

2.引入公共片段

引入公共片段:th:insert/replace/include="~{模板名(html文件名)::片段名}"
~{}可省略
行内写法:[[~{}]],[(~{})] ~{}不可省略

    <div th:insert="~{test::test}">div>
    <div th:replace="~{test::test}">div>
    <div th:include="~{test::test}">div>

3.默认效果

th:insert:将公共片段,整个插入到原有标签内
th:replace:用公共片段代替原有标签
th:include:将公共片段的内容,放入原有标签内
原有标签中的内容会被替代

   
    <div>
        <test>
             <p>thymeleafp>
        test>
    div>

  
    <test>
        <p>thymeleafp>
    test>

   
    <div>
        <p>thymeleafp>
    div>

你可能感兴趣的:(spring)