SPR-4518 - @RequestMapping methods returning null have an implicit ModelAndView created

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1049 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Arjen Poutsma
2009-04-22 12:57:30 +00:00
parent 359af039a5
commit 9818f88199
3 changed files with 34 additions and 2 deletions
@@ -25,12 +25,14 @@ import java.lang.annotation.Target;
import org.springframework.http.HttpStatus;
/**
* Marks an exception class with the status code and reason that should be returned whenever said exception is thrown.
* Marks a method or exception class with the status code and reason that should be returned. The status code is applied
* to the HTTP response when the handler method is invoked, or whenever said exception is thrown.
*
* @author Arjen Poutsma
* @see org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver
* @since 3.0
*/
@Target(ElementType.TYPE)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ResponseStatus {
@@ -75,6 +75,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.annotation.support.HandlerMethodInvoker;
import org.springframework.web.bind.annotation.support.HandlerMethodResolver;
@@ -672,6 +673,13 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen
ExtendedModelMap implicitModel,
ServletWebRequest webRequest) {
if (handlerMethod.isAnnotationPresent(ResponseStatus.class)) {
ResponseStatus responseStatus = handlerMethod.getAnnotation(ResponseStatus.class);
HttpServletResponse response = webRequest.getResponse();
response.setStatus(responseStatus.value().value());
responseArgumentUsed = true;
}
if (returnValue instanceof ModelAndView) {
ModelAndView mav = (ModelAndView) returnValue;
mav.getModelMap().mergeAttributes(implicitModel);