Thymeleaf 데코레이터-특정 페이지의 사용자 지정 바닥 글로 레이아웃에서 바닥 글을 바꾸는 방법

m.aibin

내 질문은-두 개의 파일이 있습니다 : layout.html :

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
th:fragment="layout">
<head>
<title >Layout page</title>    
</head>
<body>
<header>
  <h1>My website</h1>
</header>
<section th:include="this :: content">
  <p>Page content goes here</p>
</section>
<footer th:fragment="footer" >
  <p>My footer</p>      
</footer>  
</body>
</html>

그리고 index.html :

<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
th:include="layout :: layout">
<head>
<title>Index page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
 <h2>Hello World!</h2>

<section class="seedstarterlist" th:fragment="content" >
    <form action="#" th:action="@{/add}" th:object="${user}" method="post">
        <table>
            <tbody>
                <tr>
                    <td>name</td>
                    <td><input type="text" th:field="*{name}"  /></td>
                </tr>
                <tr>
                    <td>surname</td>
                    <td><input type="text" th:field="*{surname}"  /></td>
                </tr>
                <tr>
                    <td>email</td>
                    <td><input type="text" th:field="*{email}"  /></td>
                </tr>
                <tr>
                    <td>street</td>
                    <td><input type="text" th:field="*{street}"  /></td>
                </tr>
                <tr>
                    <td>postcode</td>
                    <td><input type="text" th:field="*{postcode}"  /></td>
                </tr>
                <tr>
                    <td>city</td>
                    <td><input type="text" th:field="*{city}"  /></td>
                </tr>
                <tr>
                    <td>district</td>
                    <td><input type="text" th:field="*{district}"  /></td>
                </tr>
                <tr>
                    <td>country</td>
                    <td><input type="text" th:field="*{country}"  /></td>
                </tr>
                <tr>
                    <td>nationality</td>
                    <td><input type="text" th:field="*{nationality}"  /></td>
                </tr>
                <tr>
                    <td>phoneNumber</td>
                    <td><input type="text" th:field="*{phoneNumber}"  /></td>
                </tr>
                <tr>
                    <td>avatar</td>
                    <td><input type="text" th:field="*{avatar}"  /></td>
                </tr>
                <tr>
                    <td>password</td>
                    <td><input type="text" th:field="*{password}"  /></td>
                </tr>
                <tr>
                    <td>status</td>
                    <td><input type="text" th:field="*{status}"  /></td>
                </tr>
                <tr>
                    <td>sex</td>
                    <td><input type="text" th:field="*{sex}"  /></td>
                </tr>
                <tr>
                    <td>birthdate</td>
                    <td><input type="text" th:field="*{birthdate}"  /></td>
                </tr>
                <tr>
                    <td colspan="2">
                        <button type="submit" name="add">Add User</button>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</section>
<footer th:fragment="footer" >
  <p>My custom footer</p>      
</footer>

index.html 페이지에서만 사용자 지정 바닥 글을 갖고 싶습니다. 레이아웃은 잘 작동하지만이 특정 페이지에서 바닥 글을 재정의하고 싶습니다. 작동하지 않습니다.

도움이 필요하세요?

m.aibin

대답은 접근 방식을 변경하고 ThymeLeaf Layout Dialect를 사용해야한다는 것입니다. Spring 구성 파일에 추가 템플릿 엔진을 등록했습니다.

<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
  <property name="additionalDialects">
    <set>
      <bean class="nz.net.ultraq.thymeleaf.LayoutDialect"/>
    </set>
  </property>
</bean>

html 상단의 선언을 다음과 같이 변경하십시오.

<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
  layout:decorator="layout.html">

누군가를 도울 수 있기를 바랍니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관