在Tg类中,有Public ListField1,其中包括Tzzz类。我需要Tzzz在HTML中显示的次数如List中所述。有显示一个Tzzz的HMTL代码:

<div class="section3">
        <span class="section3_label1">{{tv_stopH}}</span><span class="section3_label2">{{tv_sch}}</span>
    </div>
    <div class="section3_1">
    <div class="section3_1_textblock1">
        <span class="label_alt">{{arri}}</span><br />
        {{tv_add}}
    </div>
    <div class="section3_1_textblock2">
        <span class="label_alt">{{cont}}</span><br />
        {{tv_cont}}
    </div>
    <div class="section3_1_textblock1">
        {{#pic1}}
        <span class="label_alt">{{tv_refName1}}:</span>&nbsp;{{tv_ref1}}<br />
        {{/pic1}}
    </div>


Tg类:

public class Tg
{
    public List<Tzzz> Field1;

    public String Value1;
    public String Value2;
    ............


Tzzz类:

public class Tzzz
{
public Integer tv_stopH;
public String tv_sch;
public String arri;
public String cont;
........


一个对象Tzzz的JAVA代码:

    Template tmpl = Mustache.compiler().escapeHTML(false).compile(template);
    Map<String, Object> data = new HashMap<String, Object>();

    .......
    value = tzzz.tv_stopH;
    data.put("tv_stopH", value);

    value = tzzz.tv_sch;
    data.put("tv_sch", value);

    value = tzzz.arri;
    data.put("arri", value);

    value = tzzz.tv_add;
    data.put("tv_add", value);

    value = tzzz.cont;
    data.put("cont", value);


    if(tzzz.tv_refName1.length() > 0)
    {
        data.put("pic1", True);

        value = tzzz.tv_refName1;
        data.put("tv_refName1", value);

        value = tzzz.tv_ref1;
        data.put("tv_ref1", value);
    }

最佳答案

您使用{{#list_key_name}}...{{/list_key_name}}

因此,如果您有一个变量List<SomeObject> foo并将其添加到Map<String, Object> params; params.put("foo", foo),则模板将如下所示。

<ul>
    {{#foo}}
    <li><!--interpolate values from SomeObject --></li>
    {{/foo}}
</ul>


这些内容在documentation中进行了解释。除非端口出于某种原因决定破坏“规范”,否则它应该在不同的实现中工作。

09-07 22:04