2 回答
TA贡献1824条经验 获得超8个赞
Mustache.Visitor用于访问模板中的标签而不执行它
例子:
List<String> vars = new ArrayList<>();
Template tmpl = ... // compile your template
tmpl.visit(new Mustache.Visitor() {
// I assume you don't care about the raw text or include directives
public void visitText(String text) {}
// You do care about variables, per your example
public void visitVariable(String name) {vars.add("Variable: " + name); }
// Also makes sense to visit nested templates.
public boolean visitInclude(String name) { vars.add("Include: " + name); return true; }
// I assume you also care about sections and inverted sections
public boolean visitSection(String name) { vars.add("Section: " + name); return true; }
public boolean visitInvertedSection(String name) { vars.add("Inverted Section: " + name); return true; }
});
Visitor从 1.15 版开始可用jmustache:
<groupId>com.samskivert</groupId>
<artifactId>jmustache</artifactId>
<version>1.15</version>
TA贡献1801条经验 获得超15个赞
添加回答
举报