Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to remove XML header for spring mvc @ResponseBody?
    text
    copied!<pre><code>@RequestMapping(method = RequestMethod.GET, produces = "application/xml") @ResponseBody </code></pre> <p>resonpse xml like this</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;xml&gt; &lt;code&gt;0&lt;/code&gt; &lt;msg&gt;success&lt;/msg&gt; &lt;/xml&gt; </code></pre> <p>however I the response I want like this</p> <pre><code>&lt;xml&gt; &lt;code&gt;0&lt;/code&gt; &lt;msg&gt;success&lt;/msg&gt; &lt;/xml&gt; </code></pre> <p>How to remove the XML header by annotation or XML config file? Thanks. </p> <p><strong>I have solved this problem</strong>.</p> <ol> <li><p>Use this XML Conventor</p> <pre><code> &lt;bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"&gt; &lt;property name="marshaller" ref="marshaller"&gt;&lt;/property&gt; &lt;property name="unmarshaller" ref="marshaller"&gt;&lt;/property&gt; &lt;/bean&gt; </code></pre></li> <li><p>Config the Marshaller bean</p> <pre><code>&lt;bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller" id="marshaller"&gt; &lt;property name="classesToBeBound"&gt; &lt;list&gt; &lt;value&gt;com.xx.entity.Message&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="marshallerProperties"&gt; &lt;map&gt; &lt;entry&gt; &lt;key&gt; &lt;util:constant static-field="javax.xml.bind.Marshaller.JAXB_FRAGMENT"/&gt; &lt;/key&gt; &lt;value type="java.lang.Boolean"&gt;true&lt;/value&gt; &lt;/entry&gt; &lt;/map&gt; &lt;/property&gt; </code></pre> <p></p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload