Springmvc multi-view
Is a multi-view method can return data json / xml format of
The first step: Import xml format support jar package
spring-oxm-3.2.0.RC2.jar
Step Two: Configure support for multiple views
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <!-- 配置支持媒体类型 --> <property name="contentNegotiationManager"> <bean class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> <property name="mediaTypes"> <map> <entry key="json" value="application/json"></entry> <entry key="xml" value= "the Application / xml" > </ entry > </ the Map > </ Property > </ bean > </ Property > <-! specify a default view -> < Property name = "defaultViews" > <-! Support a plurality of views -> < List > <-! support josn tabular view -> < the bean class = "org.springframework.web.servlet.view.json.MappingJacksonJsonView" /> <-! XML format view supports -> <bean class="org.springframework.web.servlet.view.xml.MarshallingView"> <constructor-arg> <bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> <property name="classesToBeBound"> <list> <value>com.backoffice.model.Student</value> </list> </property> </bean> </constructor-arg> </bean> </list> </property> </bean>
The third step: the controller provides an interface
Note JavaBeans objects need to declare a comment
Step Four: Test
Return json data
Return xml data