thymeleaf not working(th:replace, th:fragment)

Viewed 247

I'm using thymeleaf, but main.html only plays content without headers or footers.

I set the header and footer to th:replace in default.html, but when I open the chrome, only the contents appear.

header.html

<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">

    <header th:fragment="header">
        <h1>headerrrrrrrrrrrrrr</h1>
    </header>
</html>

footer.html

<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">

    <footer th:fragment="footer">
        <h1>footerrrrrrrrrrrrrr</h1>
    </footer>
</html>

default.html

<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <header th:replace="fragments/header :: header"></header>

    <div layout:fragment="content"></div>

    <footer th:replace="fragments/footer :: footer"></footer>
</body>
</html>

main.html

<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="~{layout/default}">
<head>
    <meta charset="UTF-8">
    <title>2222</title>
</head>
<body>
    <div layout:fragment="content">
        <div class="container">
          <h1>mainnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn</h1>
        </div>
    </div>
</body>
</html>

gradle

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
    implementation 'org.springframework.boot:spring-boot-starter-web'

    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.projectlombok:lombok'
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
0 Answers
Related