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风格的服务接口
1 @RequestMapping(value = "/gadgets/{id}",
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服务接口的调用。
1 // 使用getForObject执行查询操作
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能与我们早日见面。
最后,由于本人对Rest技术了解还不是太深入,也希望大家能多提些意见和建议。
分享到:
相关推荐
spring-boot-web代码示例,是IDEA的项目工程,使用restful风格实现增删查改,静态数据
springboot2.4增删改查示例,结合B站尚硅谷教程使用,给初学者使用,spingboot2.4相较于1.5版本的用法有些变化,经验者绕行。
spring 3.0 应用springmvc 构造RESTful
NULL 博文链接:https://carvin.iteye.com/blog/786817
NULL 博文链接:https://nothing-whoami.iteye.com/blog/1740669
全新的Spring 3.0提供了全面的RESTful Web服务支持,以及一个新的表达式语言。其tc服务器此次也提供了全新的开发者版本,可以免费供开发者下载,用于调试其Spring应用。 Spring 3.0中,新的表达式语言名叫Spring ...
spring_3.0_应用springmvc_构造RESTful_URL_详细讲解
instrumented-restful-fast-request-pro-2023.1.7.1 可用版,亲测,可用。
Java SpringBoot 课程 restful crud 实验资源 ...GitHub中有源码 https://github.com/kevinkda/MarkdownRepository/tree/master/Develop%20Demo/Java%20Framework/Spring/SpringBoot/spring-boot-restful-crud-01
Pandax是Go语言开源的企业级低代码物联网平台开发框架,基于go-restful+Vue3.0+TypeScript+vite3+element-Plus的前后端分离开发。支持设备管控,规则链,云组态,可视化大屏,报表设计器,表单设计器,代码生成器,...
Spring MVC--6.RESTful SpringMVC CRUD
全新的Spring 3.0提供了全面的RESTful Web服务支持,以及一个新的表达式语言。其tc服务器此次也提供了全新的开发者版本,可以免费供开发者下载,用于调试其Spring应用。 Spring 3.0中,新的表达式语言名叫Spring ...
对应博客中的spring3.0支持restful的demo源代码,由于容量原因我把lib下面的包给去掉了。如果有需要lib下面用的jar包的话就给我留言,留个email,我看到后就发过去。
资源来自pypi官网。 资源全名:flask-restful-swagger-3-0.2.0.tar.gz
python开发,基于flask-restful 的中小型项目,restful风格API接口开发实例,以mongodb作为数据库 python开发,基于flask-restful 的中小型项目,restful风格API接口开发实例,以mongodb作为数据库python开发,基于...
Spring-Boot-HBase-RESTful Spring-Boot-HBase-RESTful ##安装 brew install hadoop hbase zookeeper## HBase入门 start-hbase.sh start sudo /usr/local/Cellar/zookeeper/3.4.8/bin/zkServer start参考示例代码: ...
资源分类:Python库 所属语言:Python 资源全名:FastApi-RESTful-0.2.4.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
要使用go-restful软件包的v3版本,您需要导入此软件包的v2,例如: import ( restfulspec "github.com/emicklei/go-restful-openapi/v2" restful "github.com/emicklei/go-restful/v3"):copyright:2017-2020,er
主要介绍了Python中Flask-RESTful编写API接口(小白入门),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧