- 浏览: 543663 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
jsdsh:
自己写的就是不一样.
Spring3 MVC 注解(二)---@RequestMapping -
jsdsh:
吼,非常吼.学习了
Spring3 MVC 注解(一)---注解基本配置及@controller和 @RequestMapping 常用解释 -
爱情是一种错觉:
我爱你 i love 你[color=red][/color] ...
Spring3 MVC 注解(一)---注解基本配置及@controller和 @RequestMapping 常用解释 -
fs08ab:
大哥,目前这个问题有什么可靠的解决方案吗
@ResponseBody注解 -
lhs295988029:
说的很清楚,明白了~
Spring3 MVC 注解(一)---注解基本配置及@controller和 @RequestMapping 常用解释
Spring3 MVC Restful 多请求类型(json,xml,k-v),多视图配置(Json,Xml,JSP,Freemarker,Volacity等)
- 博客分类:
- spring
beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.xxx." />
<aop:aspectj-autoproxy proxy-target-class="true" />
<context:annotation-config />
<import resource="classes/DataSource.xml"/>
<import resource="classes/applicationContext.xml"/>
<mvc:interceptors>
<bean class="com.globeway.web.servlet.intercept.JsonGetInterceptor" />
</mvc:interceptors>
<bean id="defaultAnnotationHandlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" ></bean>
<!-- 配置多请求数据类型,如json xml-->
<bean id="annotationMethodHandlerAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
<property name="messageConverters">
<list>
<!-- 解析json请求数据,将json转换为java对象-->
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
<!-- 解析xml请求数据,将xml转换为java对象-->
<bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<constructor-arg>
<bean class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="streamDriver" >
<bean class="com.thoughtworks.xstream.io.xml.DomDriver"/>
</property>
<property name="autodetectAnnotations" ><value>true</value></property>
<!--可以与xml互换的对象,需要使用XStream的注解,注解的使用方法请参XStream官网-->
<property name="annotatedClasses">
<list>
<value>com.xxx.XxxxDTO</value>
</list>
</property>
</bean>
</constructor-arg>
</bean>
<bean class="org.springframework.http.converter.FormHttpMessageConverter"/>
<bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
<!--可以增加其他数据类型,请参考spring的API-->
</list>
</property>
</bean>
</bean>
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<!-- .ftl文件存放的根目录-->
<property name="templateLoaderPath" value="/WEB-INF/ftl/"/>
<property name="freemarkerVariables">
<map>
<entry key="xml_escape" value-ref="fmXmlEscape"/>
</map>
</property>
<!--可以增加其他freemarker的配置,详情请参阅FreeMarkerConfigurerAPI-->
</bean>
<bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape"/>
<bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="defaultContentType" value="application/json" />
<property name="mediaTypes">
<map>
<entry key="html" value="text/html" />
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
</map>
</property>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="cache" value="true"/>
<property name="prefix" value=""/>
<property name="suffix" value=".ftl"/>
<property name="exposeSpringMacroHelpers" value="true"/>
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 可加入其他视图技术如 volacity jstl等-->
</list>
</property>
<property name="defaultViews">
<list>
<!-- 输出为JSON数据-->
<bean
class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
</bean>
<!-- 输出为xml数据-->
<bean id="marshallingView" class="org.springframework.web.servlet.view.xml.MarshallingView">
<property name="marshaller">
<bean id="xStreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller" >
<property name="autodetectAnnotations" value="true"/>
</bean>
</property>
<property name="contentType" value="application/xml" />
</bean>
</list>
</property>
</bean>
<bean id="exceptionResolver"
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="defaultErrorView" value="/commons/error" />
<property name="exceptionMappings">
<props>
</props>
</property>
</bean>
</beans>
Controller:
@Controller
@RequestMapping("/register/person")
public class PersonController {
@RequestMapping(method=RequestMethod.GET)
public ModelAndView list() {
HashMap<String,Object> model = new HashMap<String,Object>();
model.put("pager", pager);
return new ModelAndView("/register/person/personList",model );
}
}
http://xxxx:pp/register/person
ajax:
jQuery.ajax({
url: '/register/person',
contentType: "application/json",//application/xml
processData: true,//contentType为xml时,些值为false
dataType: "html",//json--返回json数据类型;xml--返回xml
data: {},
success: function(data) {
},
error:function(e){
}
});
发表评论
-
Spring @Transactional
2011-08-01 11:53 1808Spring事务的传播行为 在service类前加上@ ... -
spring mvc java.lang.IllegalStateException: Errors/BindingResult argument declar
2011-01-21 10:21 5052关于BindingResult Spring ... -
kaptcha 验证码在spring mvc 中的使用
2010-11-11 14:46 15404kaptcha 是一个非常实用的验证码生成工具。有了它,你可 ... -
@ResponseBody注解
2010-11-04 17:44 29820在SpringMVC中可以在Contr ... -
spring 标签介绍
2010-10-27 14:42 3034Spring 标记库分类如下: 1、spring:has ... -
spring roo
2010-10-22 14:50 3154Spring Roo 是一种 Spring 开发的辅助工具,当 ... -
spring mvc 实现的验证码功能
2010-10-19 15:56 8810import java.awt.BasicStroke; i ... -
spring3 Validation, Data Binding, and Type Conversion
2010-10-18 17:52 38075. Validation, Data Binding, ... -
spring 基于注解的控制器配置
2010-10-18 16:10 385913.12. 基 于注解的控制器配置 现时对于一些类型的配 ... -
打散 <mvc:annotation-driven>
2010-10-18 13:10 4762Spring3.0的基于注解的MVC非常好用,特别在加入了新的 ... -
spring mvc使用注解后的校验和绑定处理
2010-10-12 15:18 1389spring mvc使用注解后,依然可以使用自带的Valida ... -
使用 Spring 2.5 基于注解驱动的 Spring MVC
2010-10-12 10:45 1559概述 继 Spring 2.0 对 Spring MV ... -
Spring MVC的表单控制器
2010-10-11 15:36 3927概述 大多数Web应 ... -
context:component-scan
2010-10-08 13:33 44631. 扫描过滤方式 过滤器类型 说明 注释 假如 com.ba ... -
Spring MVC
2010-09-21 16:12 4404Spring提供了一个细致完整的MVC框架。该框架为模型、视图 ... -
领略Spring 3.x 时代的Spring MVC
2010-09-21 16:07 2000鼎鼎大名的Spring框架3.0版在12月5日由其作者之 ... -
Spring入门之三: 进入Spring MVC
2010-09-13 11:04 2435Spring入门之三: 进入Sprin ... -
Spring3 MVC (三)---请求处理方法 参数及返回值总结
2010-09-13 10:50 8559@RequestMapping("/xx ... -
Spring3 MVC 注解(二)---@RequestMapping
2010-09-13 10:47 155641 问题:有多个 @RequestMapping @ ... -
Spring3 MVC 注解(一)---注解基本配置及@controller和 @RequestMapping 常用解释
2010-09-13 10:46 93107一:配置web.xml 1)问题:spri ...
相关推荐
最新spring3 mvc restful urlrewrite jquery json freemarker整合架构jar图片,欢迎下载: 说明比较少,群号:24172014,不懂来问,已懂讨论
spring mvc restful service,支持string, json, xml, maven工程,可以直接运行
使用Spring4 MVC 构建RESTful服务器,输出JSON格式的数据结构
instrumented-restful-fast-request-pro-2023.1.7.1 可用版,亲测,可用。
使用Spring 3 来创建 RESTful Web Services
使用Spring4 MVC 构建RESTful服务器,输出JSON格式的数据结构
3.Spring MVC 请求参数的获取案例 4.Spring MVC 域对象共享数据案例 5.Spring MVC @ModelAttribute 注解案例 6.Spring MVC 国际化案例 7.Spring MVC 请求转发与请求重定向案例 8.Spring MVC 下载 Excel 文档的需求...
springboot2.4增删改查示例,结合B站尚硅谷教程使用,给初学者使用,spingboot2.4相较于1.5版本的用法有些变化,经验者绕行。
本书共计10章,分别介绍了快速搭建Spring Web应用、精通MVC结构、URL映射、文件上传与错误处理、创建Restful应用、保护应用、单元测试与验收测试、优化请求、将Web应用部署到云等内容,循序渐进地讲解了Spring MVC4...
cxf集成Spring的restful WebService接口以Json形式表现的完整代码,适合新入门在学WebService的小伙伴们参考,希望对你们有帮助!
在本示例中,我们将向您展示如何将对象转换成json格式并通过spring mvc框架返回给用户。 使用技术及环境: Spring 3.2.2.RELEASE Jackson 1.9.10 JDK 1.6 Eclipse 3.6 Maven 3 PS:在spring 3 中,要输出json...
Spring MVC RESTFUL接口实例和android测试客户端
本资源类似于 Postman 的 IDEA 插件Restful Fast Request,在IDEA安装该插件后,找到插件安装目录,【C:\\... API Buddy\\lib】替换掉里面的jar文件【instrumented-restful-fast-request-pro-2023.1.7.1.jar】即可使用
java -jar target/spring-boot-restful-api-1.0-SNAPSHOT.jar 将浏览器指向 curl -X POST -d '{ "customerid": "1234567", "password": "password12" , "first": "Subhasis","last": "samal", "gender": "Male", ...
spring-boot-web代码示例,是IDEA的项目工程,使用restful风格实现增删查改,静态数据
Pro RESTful APIs Design Build and Integrate with REST JSON XML and JAX-RS 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn...
主要介绍了spring mvc实现Restful返回xml格式数据的相关资料,需要的朋友可以参考下
- AJAX、JSON、XML 5. 框架和工具: - MyBatis - Hibernate - Maven、Gradle - Git、SVN - IntelliJ IDEA、Eclipse 6. 微服务: - RESTful API - Spring Cloud Netflix - Docker、Kubernetes 7. ...
Flask-SQLALchemy-RESTFUL-API, 带有 Flask 和 Sqlalchemy的RESTFUL JSON API 教程和解释http://techarena51.com/index.php/buidling-a-database-driven-restful-json-api-in-python-3-with-flask-flask-restful