polishing
This commit is contained in:
parent
6b93f41f3a
commit
461b488eee
|
|
@ -114,23 +114,26 @@ import org.springframework.web.util.UrlPathHelper;
|
||||||
import org.springframework.web.util.WebUtils;
|
import org.springframework.web.util.WebUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the {@link org.springframework.web.servlet.HandlerAdapter} interface that maps handler methods
|
* Implementation of the {@link org.springframework.web.servlet.HandlerAdapter} interface
|
||||||
* based on HTTP paths, HTTP methods and request parameters expressed through the {@link RequestMapping} annotation.
|
* that maps handler methods based on HTTP paths, HTTP methods and request parameters
|
||||||
|
* expressed through the {@link RequestMapping} annotation.
|
||||||
*
|
*
|
||||||
* <p>Supports request parameter binding through the {@link RequestParam} annotation. Also supports the {@link
|
* <p>Supports request parameter binding through the {@link RequestParam} annotation.
|
||||||
* ModelAttribute} annotation for exposing model attribute values to the view, as well as {@link InitBinder} for binder
|
* Also supports the {@link ModelAttribute} annotation for exposing model attribute
|
||||||
* initialization methods and {@link SessionAttributes} for automatic session management of specific attributes.
|
* values to the view, as well as {@link InitBinder} for binder initialization methods
|
||||||
|
* and {@link SessionAttributes} for automatic session management of specific attributes.
|
||||||
*
|
*
|
||||||
* <p>This adapter can be customized through various bean properties. A common use case is to apply shared binder
|
* <p>This adapter can be customized through various bean properties.
|
||||||
* initialization logic through a custom {@link #setWebBindingInitializer WebBindingInitializer}.
|
* A common use case is to apply shared binder initialization logic through
|
||||||
|
* a custom {@link #setWebBindingInitializer WebBindingInitializer}.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
* @since 2.5
|
||||||
* @see #setPathMatcher
|
* @see #setPathMatcher
|
||||||
* @see #setMethodNameResolver
|
* @see #setMethodNameResolver
|
||||||
* @see #setWebBindingInitializer
|
* @see #setWebBindingInitializer
|
||||||
* @see #setSessionAttributeStore
|
* @see #setSessionAttributeStore
|
||||||
* @since 2.5
|
|
||||||
*/
|
*/
|
||||||
public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||||
implements HandlerAdapter, Ordered, BeanFactoryAware {
|
implements HandlerAdapter, Ordered, BeanFactoryAware {
|
||||||
|
|
@ -451,9 +454,8 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||||
* @see ServletRequestDataBinder#bind(javax.servlet.ServletRequest)
|
* @see ServletRequestDataBinder#bind(javax.servlet.ServletRequest)
|
||||||
* @see ServletRequestDataBinder#convertIfNecessary(Object, Class, org.springframework.core.MethodParameter)
|
* @see ServletRequestDataBinder#convertIfNecessary(Object, Class, org.springframework.core.MethodParameter)
|
||||||
*/
|
*/
|
||||||
protected ServletRequestDataBinder createBinder(
|
protected ServletRequestDataBinder createBinder(HttpServletRequest request, Object target, String objectName)
|
||||||
HttpServletRequest request, Object target, String objectName) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
return new ServletRequestDataBinder(target, objectName);
|
return new ServletRequestDataBinder(target, objectName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -466,7 +468,6 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||||
* @throws Exception in case of errors
|
* @throws Exception in case of errors
|
||||||
*/
|
*/
|
||||||
protected HttpInputMessage createHttpInputMessage(HttpServletRequest servletRequest) throws Exception {
|
protected HttpInputMessage createHttpInputMessage(HttpServletRequest servletRequest) throws Exception {
|
||||||
|
|
||||||
return new ServletServerHttpRequest(servletRequest);
|
return new ServletServerHttpRequest(servletRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -479,7 +480,6 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||||
* @throws Exception in case of errors
|
* @throws Exception in case of errors
|
||||||
*/
|
*/
|
||||||
protected HttpOutputMessage createHttpOutputMessage(HttpServletResponse servletResponse) throws Exception {
|
protected HttpOutputMessage createHttpOutputMessage(HttpServletResponse servletResponse) throws Exception {
|
||||||
|
|
||||||
return new ServletServerHttpResponse(servletResponse);
|
return new ServletServerHttpResponse(servletResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -833,12 +833,11 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||||
handleResponseBody(returnValue, webRequest);
|
handleResponseBody(returnValue, webRequest);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (returnValue instanceof HttpEntity) {
|
else if (returnValue instanceof HttpEntity) {
|
||||||
handleHttpEntityResponse((HttpEntity<?>) returnValue, webRequest);
|
handleHttpEntityResponse((HttpEntity<?>) returnValue, webRequest);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
else if (returnValue instanceof ModelAndView) {
|
||||||
if (returnValue instanceof ModelAndView) {
|
|
||||||
ModelAndView mav = (ModelAndView) returnValue;
|
ModelAndView mav = (ModelAndView) returnValue;
|
||||||
mav.getModelMap().mergeAttributes(implicitModel);
|
mav.getModelMap().mergeAttributes(implicitModel);
|
||||||
return mav;
|
return mav;
|
||||||
|
|
@ -884,10 +883,8 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||||
if (returnValue == null) {
|
if (returnValue == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpInputMessage inputMessage = createHttpInputMessage(webRequest);
|
HttpInputMessage inputMessage = createHttpInputMessage(webRequest);
|
||||||
HttpOutputMessage outputMessage = createHttpOutputMessage(webRequest);
|
HttpOutputMessage outputMessage = createHttpOutputMessage(webRequest);
|
||||||
|
|
||||||
writeWithMessageConverters(returnValue, inputMessage, outputMessage);
|
writeWithMessageConverters(returnValue, inputMessage, outputMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -898,7 +895,6 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||||
}
|
}
|
||||||
HttpInputMessage inputMessage = createHttpInputMessage(webRequest);
|
HttpInputMessage inputMessage = createHttpInputMessage(webRequest);
|
||||||
HttpOutputMessage outputMessage = createHttpOutputMessage(webRequest);
|
HttpOutputMessage outputMessage = createHttpOutputMessage(webRequest);
|
||||||
|
|
||||||
HttpHeaders entityHeaders = responseEntity.getHeaders();
|
HttpHeaders entityHeaders = responseEntity.getHeaders();
|
||||||
if (!entityHeaders.isEmpty()) {
|
if (!entityHeaders.isEmpty()) {
|
||||||
outputMessage.getHeaders().putAll(entityHeaders);
|
outputMessage.getHeaders().putAll(entityHeaders);
|
||||||
|
|
@ -1086,7 +1082,6 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -23,13 +23,13 @@ import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotation which indicates that a method return value should be bound to the web response body. Supported for annotated
|
* Annotation which indicates that a method return value should be bound to the web response body.
|
||||||
* handler methods in Servlet environments.
|
* Supported for annotated handler methods in Servlet environments.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
* @since 3.0
|
||||||
* @see RequestBody
|
* @see RequestBody
|
||||||
* @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
|
* @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
|
||||||
* @since 3.0
|
|
||||||
*/
|
*/
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue