简体   繁体   English

如何在模板中两次解析/渲染Thymeleaf模板

[英]How to parse/render Thymeleaf template twice in template

controller.java & test.shtml controller.java和test.shtml

 model.addAttribute('id',7449226) String myTag="<a th:href='|https://stackoverflow.com/users/${id}/player7|'>link<a>" model.addAttribute('myTag',myTag) 

 <div th:utext="${myTag}"> <div> 

output result 输出结果

<div> <a  href='https://stackoverflow.com/users/7449226/player7'> link <a>  <div>

It is not clear what you want to do but i guess you want to dynamically evaluate myTag inside thymeleaf template. 目前尚不清楚您要做什么,但我想您想在百里香模板中动态评估myTag

This is done by preprocessing mechanism in Thymeleaf. 这是通过Thymeleaf中的预处理机制完成的。

Here is a snippet of what you want to do: 以下是您想做什么的摘要:

<div th:utext="__${myTag}__"><div>

Please note the preprocessing start tag and end tag ( __$ __ respectively ) 请注意预处理的开始标签结束标签分别为__ $ __

For further information please take a look at the link . 有关更多信息,请查看链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM