本文整理了Java中spark.ModelAndView
类的一些代码示例,展示了ModelAndView
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ModelAndView
类的具体详情如下:
包路径:spark.ModelAndView
类名称:ModelAndView
[英]Model And View class is used to set the name of the view and the model object to be rendered.
[中]Model And View类用于设置要渲染的视图和模型对象的名称。
代码示例来源: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: perwendel/spark
/**
* Creates a new ModelAndView object with given arguments.
*
* @param model object.
* @param viewName t be rendered.
* @return object with model and view set.
*/
public ModelAndView modelAndView(Object model, String viewName) {
return new ModelAndView(model, viewName);
}
代码示例来源: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: 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
/**
* Constructs a ModelAndView with the provided model and view name
*
* @param model the model
* @param viewName the view name
* @return the model and view
*/
public static ModelAndView modelAndView(Object model, String viewName) {
return new ModelAndView(model, viewName);
}
代码示例来源: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: perwendel/spark
/**
* Creates a new ModelAndView object with given arguments.
*
* @param model object.
* @param viewName to be rendered.
* @return object with model and view set.
*/
public ModelAndView modelAndView(Object model, String viewName) {
return new ModelAndView(model, viewName);
}
代码示例来源: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: gocd/gocd
public ModelAndView index(Request request, Response response) {
HashMap<Object, Object> object = new HashMap<Object, Object>() {{
put("viewTitle", "Elastic Agent Profiles");
}};
return new ModelAndView(object, null);
}
}
代码示例来源: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: gocd/gocd
public ModelAndView index(Request request, Response response) {
HashMap<Object, Object> object = new HashMap<Object, Object>() {{
put("viewTitle", "Config Repos");
}};
return new ModelAndView(object, null);
}
}
代码示例来源: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: gocd/gocd
public ModelAndView index(Request request, Response response) {
HashMap<Object, Object> object = new HashMap<Object, Object>() {{
put("viewTitle", "Plugins");
}};
return new ModelAndView(object, null);
}
}
代码示例来源: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: gocd/gocd
public ModelAndView index(Request request, Response response) {
Map<Object, Object> object = new HashMap<Object, Object>() {{
put("viewTitle", "Server Roles");
}};
return new ModelAndView(object, "roles/index.vm");
}
}
代码示例来源: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: gocd/gocd
private ModelAndView index(Request request, Response response) {
HashMap<Object, Object> object = new HashMap<Object, Object>() {{
put("viewTitle", "Kitchen Sink");
}};
return new ModelAndView(object, null);
}
}
代码示例来源:origin: com.sparkjava/spark-template-velocity
/**
* {@inheritDoc}
*/
@Override
public String render(ModelAndView modelAndView) {
String templateEncoding = Optional.ofNullable(this.encoding).orElse(StandardCharsets.UTF_8.name());
Template template = velocityEngine.getTemplate(modelAndView.getViewName(), templateEncoding);
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: gocd/gocd
public ModelAndView index(Request request, Response response) {
Map<Object, Object> object = new HashMap<Object, Object>() {{
put("viewTitle", "Artifact Stores");
}};
return new ModelAndView(object, "artifact_stores/index.vm");
}
}
代码示例来源: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);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!