Spring Boot 2.5.4下Thymeleaf布局layout:fragment不生效问题求助
问题根因
你使用的thymeleaf-layout-dialect布局方言中,父子模板的片段匹配规则要求父模板定义可替换片段、子模板声明替换内容时,均使用layout:fragment属性,你当前在父模板template.html中错误使用了Thymeleaf原生的th:fragment属性定义可替换内容区域,导致匹配失败无法替换。
修正步骤
找到template.html中content片段的定义代码:
<div th:fragment="content"> <p>Page content goes here</p> </div>
将属性th:fragment修改为layout:fragment即可:
<div layout:fragment="content"> <p>Page content goes here</p> </div>
补充说明
th:fragment是Thymeleaf原生属性,仅用于th:insert/th:replace/th:include等原生片段引用场景layout:fragment是thymeleaf-layout-dialect专用属性,用于layout:decorate装饰模式下的父子模板片段匹配,两者不可混用
内容的提问来源于stack exchange,提问作者Antariuz
相关产品推荐
相关产品推荐

