本文整理了Java中spark.ModelAndView.getModel()
方法的一些代码示例,展示了ModelAndView.getModel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ModelAndView.getModel()
方法的具体详情如下:
包路径:spark.ModelAndView
类名称:ModelAndView
方法名:getModel
暂无
代码示例来源:origin: gocd/gocd
@Override
public String render(ModelAndView modelAndView) {
Template template = velocityEngine.getTemplate(provider.layout(), "utf-8");
Object model = modelAndView.getModel();
if (model == null) {
model = Collections.emptyMap();
}
if (model instanceof Map) {
VelocityContext context = initialContextProvider.getVelocityContext((Map) model, controller, modelAndView.getViewName());
StringWriter writer = new StringWriter();
template.merge(context, writer);
Object meta = context.get("meta");
context.put("meta", GSON.toJson(meta));
return writer.toString();
} else {
throw new IllegalArgumentException("modelAndView must be of type java.util.Map");
}
}
}
代码示例来源:origin: pyloque/captain
@Override
public String render(ModelAndView modelAndView) {
try {
StringWriter stringWriter = new StringWriter();
Template template = configuration.getTemplate(modelAndView.getViewName());
template.process(modelAndView.getModel(), stringWriter);
return stringWriter.toString();
} catch (IOException e) {
throw new IllegalArgumentException(e);
} catch (TemplateException e) {
throw new IllegalArgumentException(e);
}
}
代码示例来源:origin: com.sparkjava/spark-template-freemarker
/**
* {@inheritDoc}
*/
@Override
public String render(ModelAndView modelAndView) {
try {
StringWriter stringWriter = new StringWriter();
Template template = configuration.getTemplate(modelAndView.getViewName());
template.process(modelAndView.getModel(), stringWriter);
return stringWriter.toString();
} catch (IOException | TemplateException e) {
throw new IllegalArgumentException(e);
}
}
代码示例来源:origin: perwendel/spark-template-engines
/**
* {@inheritDoc}
*/
@Override
public String render(ModelAndView modelAndView) {
try {
StringWriter stringWriter = new StringWriter();
Template template = configuration.getTemplate(modelAndView.getViewName());
template.process(modelAndView.getModel(), stringWriter);
return stringWriter.toString();
} catch (IOException | TemplateException e) {
throw new IllegalArgumentException(e);
}
}
代码示例来源:origin: hujiaweibujidao/Ganks-for-gank.io
/**
* {@inheritDoc}
*/
@Override
public String render(ModelAndView modelAndView) {
Template template = velocityEngine.getTemplate(modelAndView.getViewName());
Object model = modelAndView.getModel();
if (model instanceof Map) {
Map<?, ?> modelMap = (Map<?, ?>) model;
VelocityContext context = new VelocityContext(modelMap);
StringWriter writer = new StringWriter();
template.merge(context, writer);
return writer.toString();
} else {
throw new IllegalArgumentException("modelAndView must be of type java.util.Map");
}
}
代码示例来源:origin: perwendel/spark-template-engines
@Override
public String render(ModelAndView modelAndView) {
Object model = modelAndView.getModel();
if (model instanceof Map) {
String template = null;
try {
template = Resources.toString(Resources.getResource(modelAndView.getViewName()), Charsets.UTF_8);
} catch (IOException ignored) {
}
return jinjava.render(template, (Map<String, Object>) model);
} else {
throw new IllegalArgumentException("modelAndView.getModel() must return a java.util.Map");
}
}
}
代码示例来源:origin: perwendel/spark-template-engines
@Override
@SuppressWarnings("unchecked")
public String render(final ModelAndView modelAndView) {
final String templateName = modelAndView.getViewName();
if (modelAndView.getModel() instanceof Map) {
final Map<String, ?> soyMapData = (Map<String, ?>) modelAndView.getModel();
return soyTofu.newRenderer(templateName).setData(soyMapData).render();
}
throw new IllegalArgumentException("Expecting the model to be an instance of Map<String, ?>");
}
}
代码示例来源:origin: lamarios/Homedash2
public String render(ModelAndView modelAndView) {
try {
JadeTemplate template = this.configuration.getTemplate(modelAndView.getViewName());
return this.configuration.renderTemplate(template, (Map) modelAndView.getModel());
} catch (IOException var3) {
throw new IllegalArgumentException(var3);
}
}
}
代码示例来源:origin: perwendel/spark-template-engines
@Override
public String render(ModelAndView modelAndView) {
String viewName = modelAndView.getViewName();
Mustache mustache = mustacheFactory.compile(viewName);
StringWriter stringWriter = new StringWriter();
try {
mustache.execute(stringWriter, modelAndView.getModel()).close();
} catch (IOException e) {
throw new RuntimeIOException(e);
}
return stringWriter.toString();
}
}
代码示例来源:origin: com.sparkjava/spark-template-jade
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
public String render(ModelAndView modelAndView) {
try {
JadeTemplate template = configuration.getTemplate(modelAndView.getViewName());
return configuration.renderTemplate(template, (Map<String, Object>) modelAndView.getModel());
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
}
代码示例来源:origin: perwendel/spark-template-engines
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
public String render(ModelAndView modelAndView) {
try {
JadeTemplate template = configuration.getTemplate(modelAndView.getViewName());
return configuration.renderTemplate(template, (Map<String, Object>) modelAndView.getModel());
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
}
代码示例来源:origin: perwendel/spark-template-engines
@Override
public String render(ModelAndView modelAndView) {
JetTemplate template = jetEngine.getTemplate(modelAndView.getViewName());
Object model = modelAndView.getModel();
if (model instanceof Map) {
Map<String, Object> modelMap = (Map<String, Object>) model;
JetContext context = new JetContext(modelMap.size());
context.putAll(modelMap);
StringWriter writer = new StringWriter();
template.render(context, writer);
return writer.toString();
} else {
throw new IllegalArgumentException("modelAndView.getModel() must return a java.util.Map");
}
}
代码示例来源:origin: perwendel/spark-template-engines
@Override
public String render(final ModelAndView modelAndView) {
final CompiledTemplate compiledTemplate = loadTemplate(modelAndView.getViewName());
return (String) TemplateRuntime.execute(compiledTemplate, modelAndView.getModel());
}
代码示例来源:origin: airbnb/reair
@Override
@SuppressWarnings("unchecked")
public String render(ModelAndView modelAndView) {
Object model = modelAndView.getModel();
if (model instanceof Map) {
Map<String, ?> modelMap = (Map<String, ?>) model;
Context context = new Context();
context.setVariables(modelMap);
return templateEngine.process(modelAndView.getViewName(), context);
} else {
throw new IllegalArgumentException("modelAndView.getModel() must return a java.util.Map");
}
}
代码示例来源:origin: airbnb/reair
@Override
@SuppressWarnings("unchecked")
public String render(ModelAndView modelAndView) {
Object model = modelAndView.getModel();
if (model instanceof Map) {
Map<String, ?> modelMap = (Map<String, ?>) model;
Context context = new Context();
context.setVariables(modelMap);
return templateEngine.process(modelAndView.getViewName(), context);
} else {
throw new IllegalArgumentException("modelAndView.getModel() must return a java.util.Map");
}
}
代码示例来源:origin: perwendel/spark-template-engines
@Override
public String render(ModelAndView modelAndView) {
String viewName = templatesDirectory + "/" + modelAndView.getViewName();
JtwigTemplate template = JtwigTemplate.classpathTemplate(viewName);
JtwigModel model = JtwigModel.newModel((Map) modelAndView.getModel());
return template.render(model);
}
}
代码示例来源:origin: com.sparkjava/spark-template-handlebars
@Override
public String render(ModelAndView modelAndView) {
String viewName = modelAndView.getViewName();
try {
Template template = handlebars.compile(viewName);
return template.apply(modelAndView.getModel());
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
}
代码示例来源:origin: perwendel/spark-template-engines
@Override
public String render(ModelAndView modelAndView) {
String viewName = modelAndView.getViewName();
try {
Template template = handlebars.compile(viewName);
return template.apply(modelAndView.getModel());
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
}
代码示例来源:origin: aalmiray/javatrove
@Override
public final Object handle(Request request, Response response) throws Exception {
ModelAndView modelAndView = doHandle(request, response);
response.status(200);
if (shouldReturnHtml(request)) {
response.type("text/html");
return mustacheTemplateEngine.render(modelAndView);
} else {
response.type("application/json");
return objectMapper.writeValueAsString(modelAndView.getModel());
}
}
代码示例来源:origin: perwendel/spark-template-engines
/**
* {@inheritDoc}
*/
@Override
public String render(ModelAndView modelAndView) {
return Rocker.template(modelAndView.getViewName())
.bind((Map<String,Object>)modelAndView.getModel())
.render()
.toString();
}
内容来源于网络,如有侵权,请联系作者删除!