spring3 MVC restful风格
来源:互联网 发布:淘宝风格馆店铺形象图 编辑:程序博客网 时间:2024/05/22 11:30
Spring 2.5发布不久,Spring3.0项目已经是开始进行了。
包括很多新功能,如标题中提到的Restful的支持,还有Servlet3.0的支持等。
大概总结了一下,Spring3.0中会包括以下一些新特性:
1. Full scale REST support by means of additions to the Spring MVC API - already pretty detailed, and apparently going to be included in the first milestone release
2. Support for Unified EL (as seen in Spring Web Flow) - very likely part of 3.0, but no details given
3. Annotation support for declaring factory methods - as above
4 .Support for Portlet 2.0 (JSR 286), including resource requests (ResourceServingPortlet) - as above
5. "Preparations" for Servlet 3.0 specification - sounded a lot like architectural preparations not visible to the "consumer"
6. Something to fill the gap between Spring Web Flow and Spring MVC - that sounded very vague
7. Inclusion (probably generalisation) of the repeat, retry and resume semantics provided by Spring Batch - was only hinted at, no details given
8. Inclusion of the OXM support provided by Spring WS - sounded pretty definitive, but no details given
9. Some kind of site definition language for the web stack - no idea whether this is more than a rumour
10. Model-based validation for use both in server and client - as above
下面我们具体介绍一下Restful该特性。
刚才我也提到了,Spring3.0是基于其目前提供的Spring MVC框架上引入对Rest的支持,这样使其可以很好的融合到Spring中。
下面有一段代码,大家看了会更有体会。
先看一下如何发布Rest风格的服务接口
2 method = RequestMethod.GET)
3 public View getGadget(@PathParam String id) {
4 // 功能是根据 id 查询 Gadget对象
5 // 返回View对象
6 }
7
看到使用Annotation方式,代码非常简洁。@RequestMapping是对访求的资源进行服务的绑定, value指定服务的资源路径, method是指Rest风格中的CRUD的方法。
@PathParam是对资源路么参数的解析,它会自动根据提交的数据格式,解析参数值。
下面来看一下RestTemplate,对Rest服务接口的调用。
2 // (指定参数提交方式)
3 RestTemplate template = new RestTemplate();
4 Gadget gadget = template.getForObject(
5 "http://www.springify.com/gadgets/{id}",
6 Gadget.class, 1);
7
8 // 使用postForLocation 执行新增操作
9 // (指定参数提交方式,使用Map对象)
10 Map<String, String> params =
11 new HashMap<String, String>();
12 params.put("id", 42);
13 URI uri = template.postForLocation(
14 "http://www.springify.com/gadgets/{id}/features",
15 new Feature("Glows in the dark."), params);
16
17 // 删除操作的演示
18 template.delete(
19 "http://www.springify.com/gadgets/{id}", someId);
20
21
29
总结:可以看到使用Rest风格的服务发布,可以对服务资源进行统一的管理,使用发布的接口更清晰。
当然在Spring 3.0 发布之前,上述的API,annotation可能会有变动,我们也期待Spring能与我们早日见面。
- spring3 MVC restful风格
- Spring MVC Restful风格
- Spring3.0新特征-Restful support MVC
- spring3 mvc 配置restful 内容协商
- Spring MVC 示例-注解; RESTful 风格
- 基于Restful风格实现Spring MVC
- Spring MVC 支持RestFul风格尝试
- Spring MVC 示例-注解; RESTful 风格
- spring mvc完成restful风格的url
- Apache HttpClient调用Spring3 MVC Restful Web API演示
- RESTful风格
- RESTful风格
- RESTful 风格
- RESTful 风格
- RESTful风格
- RESTful风格
- Spring mvc Restful风格 静态文件访问的处理
- Spring MVC使用RESTful风格的PUT请求
- Android-BluetoothSocket建立有关蓝牙通讯的套接字
- OGRE碰撞检测MOC
- win7 remote to ubuntu 10.10 via (rdp +vnc)
- 我对BroadcastReceiver的简单理解
- 盛大糖果相册-免费图床
- spring3 MVC restful风格
- Java ThreadPoolExecutor 线程池 tips 2:偷借线程
- ZOJ2676 Network Wars
- linux2.6内核Makefile详解
- zoj 3432 Find the Lost Sock
- 空中网4k/5k月薪挑选大四实习生的线程题
- bind与eval
- 几个常用函数的实现strcpy,memcpy,memmove,strcat,strcmp
- Sql Server 2005 用户 'sa' 登录失败。该用户与可信 SQL Server 连接无关联