|
181 | 181 | </listitem>
|
182 | 182 | </itemizedlist>
|
183 | 183 | </section>
|
| 184 | + <section> |
| 185 | + <title>New HandlerMethod-based Support Classes For Annotated Controller Processing</title> |
| 186 | + <para>Spring 3.1 introduces a new set of support classes for processing requests |
| 187 | + with annotated controllers:</para> |
| 188 | + <itemizedlist> |
| 189 | + <listitem>RequestMappingHandlerMapping</listitem> |
| 190 | + <listitem>RequestMappingHandlerAdapter</listitem> |
| 191 | + <listitem>ExceptionHandlerExceptionResolver</listitem> |
| 192 | + </itemizedlist> |
| 193 | + <para>These classes are a replacement for the existing:</para> |
| 194 | + <itemizedlist> |
| 195 | + <listitem>DefaultAnnotationHandlerMapping</listitem> |
| 196 | + <listitem>AnnotationMethodHandlerAdapter</listitem> |
| 197 | + <listitem>AnnotationMethodHandlerExceptionResolver</listitem> |
| 198 | + </itemizedlist> |
| 199 | + <para>The new classes were developed in response to many requests to make |
| 200 | + annotation controller support classes more customizable and open for extension. |
| 201 | + Whereas previously you could configure a custom annotated controller method |
| 202 | + argument resolver, with the new support classes you can customize the |
| 203 | + processing for any supported method argument or return value type.</para> |
| 204 | + <itemizedlist> |
| 205 | + <listitem>See org.springframework.web.method.support.HandlerMethodArgumentResolver Javadoc</listitem> |
| 206 | + <listitem>See org.springframework.web.method.support.HandlerMethodReturnValueHandler Javadoc</listitem> |
| 207 | + </itemizedlist> |
| 208 | + <para>A second notable difference is the introduction of a |
| 209 | + <classname>HandlerMethod</classname> abstraction to represent an |
| 210 | + <interface>@RequestMapping</interface> method. This abstraction is used |
| 211 | + throughout by the new support classes as the <literal>handler</literal> instance. |
| 212 | + For example a <classname>HandlerInterceptor</classname> can cast |
| 213 | + the <literal>handler</literal> from <classname>Object</classname> to |
| 214 | + <classname>HandlerMethod</classname> and get access to the target |
| 215 | + controller method, its annotations, etc.</para> |
| 216 | + <para>The new classes are enabled by default by the MVC namespace and by |
| 217 | + Java-based configuration via <interface>@EnableWebMvc</interface>. The |
| 218 | + existing classes will continue to be available but use of the new classes is |
| 219 | + recommended going forward.</para> |
| 220 | + </section> |
| 221 | + <section> |
| 222 | + <title>Consumes and Produces <interface>@RequestMapping</interface> Conditions</title> |
| 223 | + <para>Improved support for specifying media types consumed by a method through the |
| 224 | + <literal>'Content-Type'</literal> header as well as for producible types specified |
| 225 | + through the <literal>'Accept'</literal> header. |
| 226 | + See <xref linkend="mvc-ann-requestmapping-consumes"/> and |
| 227 | + <xref linkend="mvc-ann-requestmapping-produces"/> |
| 228 | + </para> |
| 229 | + </section> |
| 230 | + <section> |
| 231 | + <title>Working With URI Template Variables In Controller Methods</title> |
| 232 | + <para>@PathVariable method arguments are now automatically added to the model. |
| 233 | + If you declare any <interface>@PathVariable</interface> arguments on a |
| 234 | + controller method you no longer need to add them to the model.</para> |
| 235 | + <para>Redirect view strings can now be URI templates. |
| 236 | + For example a controller can return <literal>"redirect:/blog/{year}/{month}"</literal>. |
| 237 | + The URI template will be expanded with variables from the model, which |
| 238 | + of course includes <interface>@PathVariable</interface> method arguments |
| 239 | + that are now automatically added to the model.</para> |
| 240 | + <para>URI template variables are now included in data binding |
| 241 | + in addition to request parameters, which are typically used for |
| 242 | + populating a model.</para> |
| 243 | + </section> |
| 244 | + <section> |
| 245 | + <title>Validation For <interface>@RequestBody</interface> Method Arguments</title> |
| 246 | + <para>An <interface>@RequestBody</interface> method argument annotated |
| 247 | + with <interface>@Valid</interface> is now automatically validated with the |
| 248 | + same <classname>Validator</classname> instance used to validate |
| 249 | + an <interface>@ModelAttribute</interface> method argument. |
| 250 | + Both the MVC namespace and <interface>@EnableWebMvc</interface> |
| 251 | + automatically configure a JSR-303 <classname>Validator</classname> adapter |
| 252 | + provided a JSR-303 implementation is available on the classpath.</para> |
| 253 | + </section> |
184 | 254 | </section>
|
185 | 255 | </chapter>
|
0 commit comments