@RequestMapping(method = RequestMethod.GET, produces = "application/xml")
@ResponseBody
このような応答xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xml>
<code>0</code>
<msg>success</msg>
</xml>
しかし、私はこのように私が望む応答です
<xml>
<code>0</code>
<msg>success</msg>
</xml>
注釈または XML 構成ファイルによって XML ヘッダーを削除するには? ありがとう。
私はこの問題を解決しました。
この XML コンバーターを使用
<bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"> <property name="marshaller" ref="marshaller"></property> <property name="unmarshaller" ref="marshaller"></property> </bean>
マーシャラー Bean を構成する
<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller" id="marshaller"> <property name="classesToBeBound"> <list> <value>com.xx.entity.Message</value> </list> </property> <property name="marshallerProperties"> <map> <entry> <key> <util:constant static-field="javax.xml.bind.Marshaller.JAXB_FRAGMENT"/> </key> <value type="java.lang.Boolean">true</value> </entry> </map> </property>