本文整理汇总了Java中com.github.mustachejava.reflect.ReflectionObjectHandler类的典型用法代码示例。如果您正苦于以下问题:Java ReflectionObjectHandler类的具体用法?Java ReflectionObjectHandler怎么用?Java ReflectionObjectHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReflectionObjectHandler类属于com.github.mustachejava.reflect包,在下文中一共展示了ReflectionObjectHandler类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: renderMustache
import com.github.mustachejava.reflect.ReflectionObjectHandler; //导入依赖的package包/类
/**
* Renders a given Mustache template using the provided value map, returning any template parameters which weren't
* present in the map.
*
* @param templateContent String representation of template
* @param values Map of values to be inserted into the template
* @param missingValues List where missing value entries will be added for any template params in
* {@code templateContent} which are not found in {@code values}
* @return Rendered Mustache template String
*/
public static String renderMustache(
String templateName,
String templateContent,
Map<String, String> values,
final List<MissingValue> missingValues) {
StringWriter writer = new StringWriter();
DefaultMustacheFactory mustacheFactory = new DefaultMustacheFactory();
mustacheFactory.setObjectHandler(new ReflectionObjectHandler() {
@Override
public Binding createBinding(String name, final TemplateContext tc, Code code) {
return new MissingValueBinding(this, name, tc, code, missingValues);
}
});
Map<String, Object> objEnv = new HashMap<>();
for (Map.Entry<String, String> entry : values.entrySet()) {
if (StringUtils.equalsIgnoreCase(entry.getValue(), "false") ||
StringUtils.equalsIgnoreCase(entry.getValue(), "true")) {
objEnv.put(entry.getKey(), Boolean.valueOf(entry.getValue()));
} else {
objEnv.put(entry.getKey(), entry.getValue());
}
}
mustacheFactory
.compile(new StringReader(templateContent), templateName)
.execute(writer, objEnv);
return writer.toString();
}
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:40,代码来源:TemplateUtils.java
示例2: testRendering
import com.github.mustachejava.reflect.ReflectionObjectHandler; //导入依赖的package包/类
@Test
public void testRendering() {
My.templatesPath("view-rendering");
MustacheJavaViewResolver viewResolver = Integrate.mustacheJavaViewResolver();
viewResolver.setCustomizer(compiler -> {
compiler.setObjectHandler(new ReflectionObjectHandler() {
@Override
public String stringify(Object object) {
return "[" + object + "]";
}
});
return compiler;
});
My.viewResolver(viewResolver);
On.get("/").view("mtmpl").mvc((req, resp) -> {
resp.model("y", "bar");
return U.map("x", "foo");
});
getReq("/");
}
开发者ID:rapidoid,项目名称:rapidoid,代码行数:28,代码来源:MustacheJavaViewResolverTest.java
注:本文中的com.github.mustachejava.reflect.ReflectionObjectHandler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论