我想创建一个车把 java 模板,例如:
"This is a sample template with {{parameter1}} {{#if object_list}} {{#each object_list}} {{object_list.somevar}} {{object_list.othervar}} {{/each}}{{/if}}"
在我可以做 object_list.something 之前,我什至不能做一个简单的循环。我尝试了以下方法:
Map<String, String> map = new HashMap<String, String>();
map.put("people", "[ Yehuda Katz, Alan Johnson, Charles Jolley ]");
map.put("k2", "v2");
System.out.println("Map: "
+ handlebars.compileInline("{{#each people}} {{@index}}:{{this}} \n {{/each}}")
.apply(map));
}
它给出了:
Map: :[B@6cd8737
:false
关于如何实现这一目标的任何指示?注意:这些参数将在 json 文件中接收,因此我实际上不能(或不想)创建对象列表。