thymeleaf 动态更换内容(Error resolving template xxx, template might not exist or might not be ......
错误解决的方法
th:replace="__${page_area}__"
加双下划线,是预处理表达式
序言
今天我用thymeleaf的时候需要实现一个功能,就是用th:fragment,th:replace实现后台传其值的动态更换内容。
比如这一句本来固定这样替换的:
<div th:replace="managment/index">
内容区域
</div>
我用变量替换了那个文本:
<div th:replace="${page_area}">
内容区域
</div>
想要后台控制替换的值,但是报错了
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [management/index::content], template might not exist or might not be accessible by any of the configured Template Resolvers (template: “common/frame” - line 131, col 18)
我翻了中文文档都没有找到解决方法,可能很少有人这么用吧,但是我在官方文档中有这样一句:
大概的意思就是:预处理表达式和普通的表达式一样,但是被两个双划线符号所包围,就像__${express0ion}__
然后我就将其改变为:
<div th:replace="__${page_area}__">
内容区域
</div>
然后就可以了