我正在已经具有thymeleaf标签如下的字符串:预处理
String html = "<span th:text="${fisrtText}"></span> Indicative Terms for a <span th:text="${currency}"></span><span th:text="${amount}"></span>M <span th:text="${type}"></span> Facility";
我上面的字符串设置为上下文变量为:
context.setVariable("topSection", html);
我我将上下文变量设置为用于替换上面字符串中的标记的值:
org.thymeleaf.context.Context context = new org.thymeleaf.context.Context();
context.setVariable("fisrtText", "This is fisrt Text");
context.setVariable("currency", "$");
context.setVariable("amount", 256.10);
context.setVariable("type", "Loan");
现在在te mplate.html我想如下得到它:
<span th:utext="@{__${topSection}__}"></span>
我期待着得到与上下文提供值替换HTML字符串。但它返回相同的HTML,因为它是没有任何处理:
<span th:text="${fisrtText}"></span> Indicative Terms for a <span th:text="${currency}"></span><span th:text="${amount}"></span>M <span th:text="${type}"></span> Facility"
任何帮助将不胜感激。
改变@至$,现在它给我一个解析错误后: –
我的HTML与一个个减少为一个跨度:文本变量。 引起:org.springframework.expression.spel.SpelParseException:表达式[] @ 0:EL1070E:解析左操作数的问题 –
@RamDuttShukla正如我在我的最后段落,它必须是一个表达式,你不能使用预处理器来解析Thymeleaf标记。 – holmis83