方式一:
参考:
http://www.mkyong.com/spring-mvc/spring-3-mvc-and-xml-example/
满足以下条件时会自动将对象转换为xml格式进行输出:
引用
As i know, when Spring see
1. Object annotated with JAXB
2. JAXB library existed in classpath
3. “mvc:annotation-driven” is enabled
4. Return method annotated with @ResponseBody
It will handle the conversion automatically.
方式二(建议使用,可以和json等方式同时开启):
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="xml" value="application/xml"/>
<entry key="json" value="application/json"/>
</map>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
<property name="marshaller">
<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>cn.flysnowxf.resp.Result</value>
</list>
</property>
</bean>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
</list>
</property>
</bean>
当请求accept=application/xml或者url以.xml结尾,将选择xml view进行处理,这里配置的xml解析器是Jaxb2Marshaller。
分享到:
相关推荐
spring mvc生成xml或json
通过配置XML和通过注释来配置Spring MVC,入门级别,Helloworld
spring-mvc.xml资源下载,本xml为springmvc最纯净版xml!
二、spring mvc 核心类与接口 三、spring mvc 核心流程图 四、spring mvc DispatcherServlet说明 五、spring mvc 双亲上下文的说明 六、springMVC-mvc.xml 配置文件片段讲解 七、spring mvc 如何访问到静态的文件,...
六、springMVC-mvc.xml 配置文件片段讲解 七、spring mvc 如何访问到静态的文件,如jpg,js,css? 八、spring mvc 请求如何映射到具体的Action中的方法? 九、spring mvc 中的拦截器: 十、spring mvc 如何使用拦截器...
首先, 我需要在你心里建立起 Spring MVC 的基本概念. 基于 Spring 的 Web 应用程序接收到 http://localhost:8080/hello.do(事实上请求路径是 /hello.do) 的请求后, Spring 将这个请求交给一个名为 helloController ...
Spring mvc 配置: WEB/INF/springmvc-servlet.xml//编码过滤器//静态资源忽略//AOP代理方式设定//拦截器配置//cglib动态代理
spring-mvc.xml spring-mybatis.xml web.xml log4j.properties,项目中需要用到的配置文件。直接可用。
二、spring mvc 核心类与接口 三、spring mvc 核心流程图 四、spring mvc DispatcherServlet说明 五、spring mvc 双亲上下文的说明 六、springMVC-mvc.xml 配置文件片段讲解 七、spring mvc 如何访问到静态的文件,...
config.properties:数据库配置文件 log4j.properties:mybatis日志文件 spring-mvc.xml:spring-MVC配置文件 spring-mybatis.xml:mybatis的配置文件 spring.xml
后台全注解式的开发(除了必要的spring和hibernate的xml配置以外) 03. 后台通过自定义注解结合一个访问拦截器实现整个系统的权限控制 04. 系统前台采用全采用的Html+jQuery开发 05. 系统前台与后台的交互全部...
spring mvc maven项目,导入IDEA后无报错,需要在IDEA中...该项目使用servlet3.0规范,无web.xml,无spring.xml等配置文件,所有的配置均通过Java Config、注解搞定,项目中还集成了log4j2技术,以及前端html文件等。
演示了spring对aop的支持,包括注解方式、基于xml方式。
spring mvc入门示例
Spring Web MVC开发 xml配置文件格式,无bean之类 Spring Web MVC开发配置文件 applicationContext
spring bean配置 运行环境:eclipse 构建工具:maven 不提供maven构建,maven用来解决jar包的依赖