|
|
|
@ -90,10 +90,10 @@ |
|
|
|
|
|
|
|
|
|
|
|
<itemizedlist> |
|
|
|
<itemizedlist> |
|
|
|
<listitem> |
|
|
|
<listitem> |
|
|
|
<para><emphasis>Clear separation of roles</emphasis>. Each role -- |
|
|
|
<para><emphasis>Clear separation of roles</emphasis>. Each role — |
|
|
|
controller, validator, command object, form object, model object, |
|
|
|
controller, validator, command object, form object, model object, |
|
|
|
<classname>DispatcherServlet</classname>, handler mapping, view |
|
|
|
<classname>DispatcherServlet</classname>, handler mapping, view |
|
|
|
resolver, and so on -- can be fulfilled by a specialized |
|
|
|
resolver, and so on — can be fulfilled by a specialized |
|
|
|
object.</para> |
|
|
|
object.</para> |
|
|
|
</listitem> |
|
|
|
</listitem> |
|
|
|
|
|
|
|
|
|
|
|
@ -468,9 +468,9 @@ |
|
|
|
<para>If you specify a multipart file resolver, the request is |
|
|
|
<para>If you specify a multipart file resolver, the request is |
|
|
|
inspected for multiparts; if multiparts are found, the request is |
|
|
|
inspected for multiparts; if multiparts are found, the request is |
|
|
|
wrapped in a <classname>MultipartHttpServletRequest</classname> for |
|
|
|
wrapped in a <classname>MultipartHttpServletRequest</classname> for |
|
|
|
further processing by other elements in the process. (See <xref |
|
|
|
further processing by other elements in the process. See <xref |
|
|
|
linkend="mvc-multipart-resolver" /> for further information about |
|
|
|
linkend="mvc-multipart" /> for further information about |
|
|
|
multipart handling).</para> |
|
|
|
multipart handling.</para> |
|
|
|
</listitem> |
|
|
|
</listitem> |
|
|
|
|
|
|
|
|
|
|
|
<listitem> |
|
|
|
<listitem> |
|
|
|
@ -1552,7 +1552,7 @@ public void populateModel(@RequestParam String number, Model model) { |
|
|
|
the return value of the <interfacename>@RequestMapping</interfacename> method |
|
|
|
the return value of the <interfacename>@RequestMapping</interfacename> method |
|
|
|
is interpreted as a model attribute rather than as a view name. |
|
|
|
is interpreted as a model attribute rather than as a view name. |
|
|
|
The view name is derived from view name conventions instead much like for methods |
|
|
|
The view name is derived from view name conventions instead much like for methods |
|
|
|
returning void -- see <xref linkend="mvc-coc-r2vnt"/>.</para> |
|
|
|
returning void — see <xref linkend="mvc-coc-r2vnt"/>.</para> |
|
|
|
|
|
|
|
|
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
@ -1581,15 +1581,15 @@ public String processSubmit(<emphasis role="bold">@ModelAttribute Pet pet</empha |
|
|
|
There are several options: </para> |
|
|
|
There are several options: </para> |
|
|
|
|
|
|
|
|
|
|
|
<itemizedlist> |
|
|
|
<itemizedlist> |
|
|
|
<listitem>It may already be in the model due to use of |
|
|
|
<listitem><para>It may already be in the model due to use of |
|
|
|
<interfacename>@SessionAttributes</interfacename> |
|
|
|
<interfacename>@SessionAttributes</interfacename> |
|
|
|
-- see <xref linkend="mvc-ann-sessionattrib"/>.</listitem> |
|
|
|
— see <xref linkend="mvc-ann-sessionattrib"/>.</para></listitem> |
|
|
|
<listitem>It may already be in the model due to an |
|
|
|
<listitem><para>It may already be in the model due to an |
|
|
|
<interfacename>@ModelAttribute</interfacename> method in the same |
|
|
|
<interfacename>@ModelAttribute</interfacename> method in the same |
|
|
|
controller -- as explained in the previous section.</listitem> |
|
|
|
controller — as explained in the previous section.</para></listitem> |
|
|
|
<listitem>It may be retrieved based on a URI template variable |
|
|
|
<listitem><para>It may be retrieved based on a URI template variable |
|
|
|
and type converter (explained in more detail below).</listitem> |
|
|
|
and type converter (explained in more detail below).</para></listitem> |
|
|
|
<listitem>It may be instantiated using its default constructor.</listitem> |
|
|
|
<listitem><para>It may be instantiated using its default constructor.</para></listitem> |
|
|
|
</itemizedlist> |
|
|
|
</itemizedlist> |
|
|
|
|
|
|
|
|
|
|
|
<para>An <interfacename>@ModelAttribute</interfacename> method is a common |
|
|
|
<para>An <interfacename>@ModelAttribute</interfacename> method is a common |
|
|
|
@ -1613,8 +1613,8 @@ public String save(@ModelAttribute("account") Account account) { |
|
|
|
<interfacename>@ModelAttribute</interfacename> method.</para> |
|
|
|
<interfacename>@ModelAttribute</interfacename> method.</para> |
|
|
|
|
|
|
|
|
|
|
|
<para>The next step is data binding. The <classname>WebDataBinder</classname> |
|
|
|
<para>The next step is data binding. The <classname>WebDataBinder</classname> |
|
|
|
class matches request parameter names -- including query string parameters and |
|
|
|
class matches request parameter names — including query string parameters and |
|
|
|
form fields -- to model attribute fields by name. Matching fields are populated |
|
|
|
form fields — to model attribute fields by name. Matching fields are populated |
|
|
|
after type conversion (from String to the target field type) has been applied |
|
|
|
after type conversion (from String to the target field type) has been applied |
|
|
|
where necessary. |
|
|
|
where necessary. |
|
|
|
Data binding and validation are covered in <xref linkend="validation"/>. |
|
|
|
Data binding and validation are covered in <xref linkend="validation"/>. |
|
|
|
@ -2408,7 +2408,7 @@ public class TimeBasedAccessInterceptor extends HandlerInterceptorAdapter { |
|
|
|
<property name="location" value="/WEB-INF/views.xml"/> |
|
|
|
<property name="location" value="/WEB-INF/views.xml"/> |
|
|
|
</bean> |
|
|
|
</bean> |
|
|
|
|
|
|
|
|
|
|
|
<lineannotation><!-- in <literal>views.xml</literal> --></lineannotation> |
|
|
|
<lineannotation><!— in <literal>views.xml</literal> --></lineannotation> |
|
|
|
|
|
|
|
|
|
|
|
<beans> |
|
|
|
<beans> |
|
|
|
<bean name="report" class="org.springframework.example.ReportExcelView"/> |
|
|
|
<bean name="report" class="org.springframework.example.ReportExcelView"/> |
|
|
|
@ -2758,7 +2758,7 @@ public class ContentController { |
|
|
|
|
|
|
|
|
|
|
|
<para>Flash attributes provide a way for one request to store attributes |
|
|
|
<para>Flash attributes provide a way for one request to store attributes |
|
|
|
intended for use in another. This is most commonly needed when redirecting |
|
|
|
intended for use in another. This is most commonly needed when redirecting |
|
|
|
-- e.g. the Post/Redirect/Get pattern. Flash attributes are saved temporarily |
|
|
|
— e.g. the Post/Redirect/Get pattern. Flash attributes are saved temporarily |
|
|
|
before the redirect (typically in the session) to be made available to the |
|
|
|
before the redirect (typically in the session) to be made available to the |
|
|
|
request after the redirect and removed immediately. |
|
|
|
request after the redirect and removed immediately. |
|
|
|
</para> |
|
|
|
</para> |
|
|
|
@ -3266,7 +3266,7 @@ public class FileUpoadController { |
|
|
|
a RESTful service scenario. All of the above examples and configuration |
|
|
|
a RESTful service scenario. All of the above examples and configuration |
|
|
|
apply here as well. However, unlike browsers that typically submit files |
|
|
|
apply here as well. However, unlike browsers that typically submit files |
|
|
|
and simple form fields, a programmatic client can also send more complex |
|
|
|
and simple form fields, a programmatic client can also send more complex |
|
|
|
data of a specific content type -- for exmaple a multipart request with |
|
|
|
data of a specific content type — for example a multipart request with |
|
|
|
a file and second part with JSON formatted data: |
|
|
|
a file and second part with JSON formatted data: |
|
|
|
<programlisting language="xml"> |
|
|
|
<programlisting language="xml"> |
|
|
|
POST /someUrl |
|
|
|
POST /someUrl |
|
|
|
@ -3287,14 +3287,14 @@ Content-Transfer-Encoding: 8bit |
|
|
|
... File Data ... |
|
|
|
... File Data ... |
|
|
|
</programlisting></para> |
|
|
|
</programlisting></para> |
|
|
|
|
|
|
|
|
|
|
|
<para>You could access the part named "meta-data" with |
|
|
|
<para>You could access the part named "meta-data" with a |
|
|
|
<interfacename>@RequestParam("meta-data") String metadata</interfacename> |
|
|
|
<interfacename>@RequestParam("meta-data") String metadata</interfacename> |
|
|
|
controller method argument. However, you would probably |
|
|
|
controller method argument. However, you would probably |
|
|
|
prefer to accept a strongly typed object initialized |
|
|
|
prefer to accept a strongly typed object initialized |
|
|
|
from the JSON formatted data in the body of the request |
|
|
|
from the JSON formatted data in the body of the request |
|
|
|
part, very similar to the way |
|
|
|
part, very similar to the way |
|
|
|
<interfacename>@RequestBody</interfacename> converts |
|
|
|
<interfacename>@RequestBody</interfacename> converts |
|
|
|
the body of a non-multipart requests to a target object |
|
|
|
the body of a non-multipart request to a target object |
|
|
|
with the help of an <classname>HttpMessageConverter</classname>.</para> |
|
|
|
with the help of an <classname>HttpMessageConverter</classname>.</para> |
|
|
|
|
|
|
|
|
|
|
|
<para>You can use the <interfacename>@RequestPart</interfacename> |
|
|
|
<para>You can use the <interfacename>@RequestPart</interfacename> |
|
|
|
@ -3303,23 +3303,22 @@ Content-Transfer-Encoding: 8bit |
|
|
|
content of a specific multipart passed through an |
|
|
|
content of a specific multipart passed through an |
|
|
|
<classname>HttpMessageConverter</classname> |
|
|
|
<classname>HttpMessageConverter</classname> |
|
|
|
taking into consideration the <literal>'Content-Type'</literal> |
|
|
|
taking into consideration the <literal>'Content-Type'</literal> |
|
|
|
header of the multipart: |
|
|
|
header of the multipart:</para> |
|
|
|
<programlisting language="java"> |
|
|
|
|
|
|
|
@RequestMapping(value="/someUrl", method = RequestMethod.POST) |
|
|
|
<programlisting language="java">@RequestMapping(value="/someUrl", method = RequestMethod.POST) |
|
|
|
public String onSubmit(<emphasis role="bold">@RequestPart("meta-data") MetaData metadata, |
|
|
|
public String onSubmit(<emphasis role="bold">@RequestPart("meta-data") MetaData metadata, |
|
|
|
@RequestPart("file-data") MultipartFile file,</emphasis>) { |
|
|
|
@RequestPart("file-data") MultipartFile file</emphasis>) { |
|
|
|
<lineannotation>// ...</lineannotation> |
|
|
|
<lineannotation>// ...</lineannotation> |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
}</programlisting> |
|
|
|
</programlisting></para> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<para>Notice how you <classname>MultipartFile</classname> |
|
|
|
<para>Notice how <classname>MultipartFile</classname> |
|
|
|
method arguments can be accessed with <interfacename>@RequestParam</interfacename> |
|
|
|
method arguments can be accessed with <interfacename>@RequestParam</interfacename> |
|
|
|
or with <interfacename>@RequestPart</interfacename> interchangeably. |
|
|
|
or with <interfacename>@RequestPart</interfacename> interchangeably. |
|
|
|
However, the <literal>@RequestPart("meta-data") MetaData</literal> |
|
|
|
However, the <literal>@RequestPart("meta-data") MetaData</literal> |
|
|
|
method argument in this case is read as JSON content |
|
|
|
method argument in this case is read as JSON content |
|
|
|
based on its <literal>'Content-Type'</literal> |
|
|
|
based on its <literal>'Content-Type'</literal> |
|
|
|
header and converted with help of the |
|
|
|
header and converted with the help of the |
|
|
|
<classname>MappingJacksonHttpMessageConverter</classname>. |
|
|
|
<classname>MappingJacksonHttpMessageConverter</classname>. |
|
|
|
</para> |
|
|
|
</para> |
|
|
|
|
|
|
|
|
|
|
|
@ -3331,8 +3330,7 @@ public String onSubmit(<emphasis role="bold">@RequestPart("meta-data") MetaData |
|
|
|
<title>Handling exceptions</title> |
|
|
|
<title>Handling exceptions</title> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<title |
|
|
|
<title id="mvc-HandlerExceptionResolver"><interfacename>HandlerExceptionResolver</interfacename></title> |
|
|
|
id="mvc-HandlerExceptionResolver"><interfacename>HandlerExceptionResolver</interfacename></title> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<para>Spring <literal>HandlerExceptionResolver</literal> implementations deal |
|
|
|
<para>Spring <literal>HandlerExceptionResolver</literal> implementations deal |
|
|
|
with unexpected exceptions that occur during controller execution. |
|
|
|
with unexpected exceptions that occur during controller execution. |
|
|
|
@ -3473,7 +3471,7 @@ public class SimpleController { |
|
|
|
should you choose to move forward with it into production.</para> |
|
|
|
should you choose to move forward with it into production.</para> |
|
|
|
|
|
|
|
|
|
|
|
<para>Convention-over-configuration support addresses the three core areas |
|
|
|
<para>Convention-over-configuration support addresses the three core areas |
|
|
|
of MVC -- models, views, and controllers.</para> |
|
|
|
of MVC — models, views, and controllers.</para> |
|
|
|
|
|
|
|
|
|
|
|
<section id="mvc-coc-ccnhm"> |
|
|
|
<section id="mvc-coc-ccnhm"> |
|
|
|
<title>The Controller |
|
|
|
<title>The Controller |
|
|
|
@ -3902,26 +3900,26 @@ public class SimpleController { |
|
|
|
|
|
|
|
|
|
|
|
<listitem> |
|
|
|
<listitem> |
|
|
|
<para><classname>Jaxb2RootElementHttpMessageConverter</classname> |
|
|
|
<para><classname>Jaxb2RootElementHttpMessageConverter</classname> |
|
|
|
converts Java objects to/from XML -- added if JAXB2 is present |
|
|
|
converts Java objects to/from XML — added if JAXB2 is present |
|
|
|
on the classpath. |
|
|
|
on the classpath. |
|
|
|
</para> |
|
|
|
</para> |
|
|
|
</listitem> |
|
|
|
</listitem> |
|
|
|
|
|
|
|
|
|
|
|
<listitem> |
|
|
|
<listitem> |
|
|
|
<para><classname>MappingJacksonHttpMessageConverter</classname> |
|
|
|
<para><classname>MappingJacksonHttpMessageConverter</classname> |
|
|
|
converts to/from JSON -- added if Jackson is present on the classpath. |
|
|
|
converts to/from JSON — added if Jackson is present on the classpath. |
|
|
|
</para> |
|
|
|
</para> |
|
|
|
</listitem> |
|
|
|
</listitem> |
|
|
|
|
|
|
|
|
|
|
|
<listitem> |
|
|
|
<listitem> |
|
|
|
<para><classname>AtomFeedHttpMessageConverter</classname> |
|
|
|
<para><classname>AtomFeedHttpMessageConverter</classname> |
|
|
|
converts Atom feeds -- added if Rome is present on the classpath. |
|
|
|
converts Atom feeds — added if Rome is present on the classpath. |
|
|
|
</para> |
|
|
|
</para> |
|
|
|
</listitem> |
|
|
|
</listitem> |
|
|
|
|
|
|
|
|
|
|
|
<listitem> |
|
|
|
<listitem> |
|
|
|
<para><classname>RssChannelHttpMessageConverter</classname> |
|
|
|
<para><classname>RssChannelHttpMessageConverter</classname> |
|
|
|
converts RSS feeds -- added if Rome is present on the classpath. |
|
|
|
converts RSS feeds — added if Rome is present on the classpath. |
|
|
|
</para> |
|
|
|
</para> |
|
|
|
</listitem> |
|
|
|
</listitem> |
|
|
|
</itemizedlist> |
|
|
|
</itemizedlist> |
|
|
|
|