简体   繁体   English

如何解析freemarker模板的以下结构?

[英]How can I parse freemarker template's following structure?

I have some problem with following: 我有以下问题:

someMethod(List recipients, String message) {

        SimpleHash model = new SimpleHash();
        model.put("message", message);

        for (String email : recipients) {
            model.put("name", email);
            String buildHTML = FreeMarkerTemplateUtils
                    .processTemplateIntoString(freemarkerConfiguration
                            .getTemplate("customMail.ftl", locale, "UTF-8"), model);
            model.remove("name");
            create(buildHTML, email);
        }
}

That's ok! 没关系! but parameter "message" has similar to the following: 但是参数“ message”与以下内容类似:

Hi, ${userName}!

Therefore, how to recognize 因此,如何识别

${userName}

if it's exist in message? 消息中是否存在?

And my template: 和我的模板:

<h1>
  <td id="message">
    ${message}
  </td>
</h1>

If I understand it well, you are saying that message itself is a small template. 如果我理解得很好,您就是说message本身只是一个小模板。 In that case, you could use <@message?interpret /> , where ?interpret will parse message as template content, and then <@.../> will invoke it. 在这种情况下,您可以使用<@message?interpret /> ,其中?interpretmessage解析为模板内容,然后<@.../>将调用它。

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

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