diff options
author | Emmanuel Bourg <ebourg@apache.org> | 2016-08-03 19:55:01 +0200 |
---|---|---|
committer | Emmanuel Bourg <ebourg@apache.org> | 2016-08-03 19:55:01 +0200 |
commit | 75a721d1019da2a2fa86e24ff439df4a224e5b19 (patch) | |
tree | 2c44c00ce2c8641cccad177177e5682e187a17ea /spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java | |
parent | 9eaca6a06af3cbceb3754de19d477be770614265 (diff) |
Imported Upstream version 4.3.2
Diffstat (limited to 'spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java')
-rw-r--r-- | spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java index d58ea7de..66fd7429 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.web.servlet; import java.util.Map; +import org.springframework.http.HttpStatus; import org.springframework.ui.ModelMap; import org.springframework.util.CollectionUtils; @@ -36,6 +37,7 @@ import org.springframework.util.CollectionUtils; * @author Rod Johnson * @author Juergen Hoeller * @author Rob Harrop + * @author Rossen Stoyanchev * @see DispatcherServlet * @see ViewResolver * @see HandlerAdapter#handle @@ -49,6 +51,9 @@ public class ModelAndView { /** Model Map */ private ModelMap model; + /** Optional HTTP status for the response */ + private HttpStatus status; + /** Indicates whether or not this instance has been cleared with a call to {@link #clear()} */ private boolean cleared = false; @@ -116,6 +121,24 @@ public class ModelAndView { } /** + * Creates new ModelAndView given a view name, model, and status. + * @param viewName name of the View to render, to be resolved + * by the DispatcherServlet's ViewResolver + * @param model Map of model names (Strings) to model objects + * (Objects). Model entries may not be {@code null}, but the + * model Map may be {@code null} if there is no model data. + * @param status an alternative status code to use for the response. + * @since 4.3 + */ + public ModelAndView(String viewName, Map<String, ?> model, HttpStatus status) { + this.view = viewName; + if (model != null) { + getModelMap().addAllAttributes(model); + } + this.status = status; + } + + /** * Convenient constructor to take a single model object. * @param viewName name of the View to render, to be resolved * by the DispatcherServlet's ViewResolver @@ -215,6 +238,22 @@ public class ModelAndView { return getModelMap(); } + /** + * Set the HTTP status to use for the response. + * @since 4.3 + */ + public void setStatus(HttpStatus status) { + this.status = status; + } + + /** + * Return the configured HTTP status for the response, if any. + * @since 4.3 + */ + public HttpStatus getStatus() { + return this.status; + } + /** * Add an attribute to the model. |