提交 b5708590 编写于 作者: A Arjen Poutsma

Moved REST views to View chapter.

上级 7b1ff585
......@@ -38,120 +38,6 @@
configuration</link> to understand the general programming model.</para>
</section>
<section id="rest-views">
<title>Views</title>
<para>Several views were added in Spring 3 to help support creating
RESTful services. They are:</para>
<itemizedlist>
<listitem>
<para><classname>AbstractAtomFeedView</classname> - returns an Atom
feed</para>
</listitem>
<listitem>
<para><classname>AbstractRssFeedView</classname> - returns a RSS
feed</para>
</listitem>
<listitem>
<para><classname>MarshallingView</classname> - returns an XML
representation using Spring's Object to XML mapping (OXM)
functionality</para>
</listitem>
</itemizedlist>
<note>
<para>Available separately is the
<classname>JacksonJsonView</classname> included as part of the Spring
JavaScript project.</para>
</note>
<section id="rest-feedview">
<title>Feed Views</title>
<para>Both <classname>AbstractAtomFeedView</classname> and
<classname>AbstractRssFeedView</classname> inherit from the base class
<classname>AbstractFeedView</classname> and are used to provide Atom
and RSS Feed views respectfully. They are based on java.net's <ulink
url="https://rome.dev.java.net">ROME</ulink> project and are located
in the package
<literal>org.springframework.web.servlet.view.feed</literal>.</para>
<para><classname>AbstractAtomFeedView</classname> requires you to
implement the <methodname>buildFeedEntries</methodname> method and
optionally override the <methodname>buildFeedMetadata</methodname>
method (the default implementation is empty), as shown below</para>
<programlisting language="java">public class SampleContentAtomView extends AbstractAtomFeedView {
@Override
protected void buildFeedMetadata(Map&lt;String, Object&gt; model, Feed feed,
HttpServletRequest request) {
// implementation omitted
}
@Override
protected List&lt;Entry&gt; buildFeedEntries(Map&lt;String, Object&gt; model,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
// implementation omitted
}
}</programlisting>
<para>Similar requirements apply for implementing
<classname>AbstractRssFeedView</classname>, as shown below</para>
<programlisting language="java">public class SampleContentAtomView extends AbstractRssFeedView {
@Override
protected void buildFeedMetadata(Map&lt;String, Object&gt; model, Channel feed,
HttpServletRequest request) {
// implementation omitted
}
@Override
protected List&lt;Item&gt; buildFeedItems(Map&lt;String, Object&gt; model,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
// implementation omitted
}
}</programlisting>
<para>The <methodname>buildFeedItems</methodname> and
<methodname>buildFeedEntires</methodname> pass in the HTTP request in
case you need to access the Locale. The HTTP response is passed in
only for the setting of cookies or other HTTP headers. The feed will
automatically be written to the response object after the method
returns.</para>
<para>For an example of creating a Atom view please refer to Alef
Arendsen's SpringSource TeamBlog <ulink
url="http://blog.springsource.com/2009/03/16/adding-an-atom-view-to-an-application-using-springs-rest-support/">entry</ulink>.</para>
</section>
<section>
<title>XML Marshalling View</title>
<para>The <classname>MarhsallingView</classname> uses a XML
<interfacename>Marshaller</interfacename> defined in the
<classname>org.springframework.oxm</classname> package to render the
response content as XML. The object to be marshalled can be set
explicitly using <classname>MarhsallingView</classname>'s
<property>modelKey</property> bean property. Alternatively, the view
will iterate over all model properties marhsall only those types that
are supported by the <interfacename>Marshaller</interfacename>. For
more information on the functionality in the
<classname>org.springframework.oxm</classname> package refer to the
chapter <link linkend="oxm">Marshalling XML using O/X
Mappers</link>.</para>
</section>
</section>
<section id="rest-method-conversion">
<title>HTTP Method Conversion</title>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册