Spring MVC中发布Restful Web服务
- 表述性(R),REST资源实际上可以用各种形式表述,包括XML,JSON甚至HTML;
- 状态(S),当使用REST的时候,我们更关注资源的状态而不是对资源所采取的行为;
- 转移(T),REST涉及转移资源数据,以另一种表述性形式从一个应用转移到另一个应用;



<!-- 启动注解驱动的spring mvc功能,注册请求url和注解pojo类方法的映射 -->
<mvc:annotation-driven/> <!-- 启动包扫描功能,以便注册带有@controller,@service,@repository,@component等注解的类为spring的bean -->
<context:component-scan base-package=“com.xxx.framework" />
@Controller
@RequestMapping(value = "/tasks")
public class TasksController { @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void putTaskRequest(@PathVariable("id") long id, @Valid String content) {
System.out.println("put");
} @RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public TaskDefinition createTaskRequest() {
System.out.println("post");
return null;
} @RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void showTaskContent(@PathVariable("id") long id) {
System.out.println(id);
} @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void killTaskRequest(@PathVariable("id") long id) {
System.out.println("kill");
}
23:18:14,723 INFO DefaultAnnotationHandlerMapping:315 - Mapped URL path [/tasks/{id}] onto handler 'tasksController'
23:18:14,724 INFO DefaultAnnotationHandlerMapping:315 - Mapped URL path [/tasks/{id}.*] onto handler 'tasksController'
23:18:14,724 INFO DefaultAnnotationHandlerMapping:315 - Mapped URL path [/tasks/{id}/] onto handler 'tasksController'
23:18:14,724 INFO DefaultAnnotationHandlerMapping:315 - Mapped URL path [/tasks] onto handler 'tasksController'
23:18:14,725 INFO DefaultAnnotationHandlerMapping:315 - Mapped URL path [/tasks.*] onto handler 'tasksController'
23:18:14,725 INFO DefaultAnnotationHandlerMapping:315 - Mapped URL path [/tasks/] onto handler 'tasksController'

Spring MVC中发布Restful Web服务的更多相关文章
- SpringBoot实战(十)之使用Spring Boot Actuator构建RESTful Web服务
一.导入依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http ...
- CRUD using Spring MVC 4.0 RESTful Web Services and AngularJS
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- [译]Spring Boot 构建一个RESTful Web服务
翻译地址:https://spring.io/guides/gs/rest-service/ 构建一个RESTful Web服务 本指南将指导您完成使用spring创建一个“hello world”R ...
- 使用 Spring 3 MVC HttpMessageConverter 功能构建 RESTful web 服务
原文地址:http://www.ibm.com/developerworks/cn/web/wa-restful/ 简介: Spring,构建 Java™ 平台和 Enterprise Edition ...
- Spring MVC 4实现RESTFul WebServices的CRUD实例和使用RestTemplate进行请求(全注解形式配置Web和Filter)
在这篇文章中,我们将使用Spring4 MVC编写一个CRUD RESTful Web服务,写一个REST客户端RestTemplate来使用这些服务.我们也将利用外部客户端测试的服务. 下面将展示核 ...
- 使用 Spring 3 来创建 RESTful Web Services(转)
使用 Spring 3 来创建 RESTful Web Services 在 Java™ 中,您可以使用以下几种方法来创建 RESTful Web Service:使用 JSR 311(311)及其参 ...
- Spring MVC 中的REST支持
本部分提供了支持 RESTful web 服务的主要 Spring 功能(或注释)的概述. @Controller 使用 @Controller 注释对将成为 MVC 中控制器的类进行注释并处理 HT ...
- 使用 Spring Boot Actuator 构建 RESTful Web 应用
Spring Boot Actuator 是 Spring Boot 的一个子项目.通过它,可以很轻易地为应用提供多种生产级服务.本教程中,你将通过构建一个应用来学习如何添加这些服务. 1. 你需要构 ...
- Spring MVC 中的基于注解的 Controller【转】
原文地址:http://my.oschina.net/abian/blog/128028 终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 H ...
随机推荐
- Hibernate主键生成策略详解
转载自:http://blog.csdn.net/wanghuan203/article/details/7562395 hibernate提供的主键生成策略,使我们可以在实体类的映射xml文件中设定 ...
- Kotlin Reference (二) Idioms
most from reference 一些常用操作 创建单例类 object 数据类data classList.Map.Array的简单操作Lazy延迟加载属性空类型?空类型表达式?..?:.?. ...
- EasyCMS在幼儿园视频直播项目实战中以redis操作池的方式应对高并发的redis操作问题
在之前的博客< EasyDarwin幼教云视频平台在幼教平台领域大放异彩!>中我们也介绍到,EasyCMS+EasyDarwin+redis形成的EasyDarwin云平台方案,在幼教平台 ...
- Oracle数据库中字段定义为Char类型,Hibernate用该字段进行动态绑定参数查询,获取不到结果的问题
一.问题背景 产生环境:oracle数据库,hibernate操作 定义了一个表 create table STORE_INFORMATION ( id CHAR(32) not null, name ...
- grunt使用
grunt例子:https://github.com/Aquarius1993/gruntDemo 1.前提是已经有npm(可以通过安装nodejs实现) 2. npm update -g npm 更 ...
- Mac怎么快速创建便签和发送附件的邮件
1.如何快速创建便签 在Mac的任意界面选中文字:shift+command+y 就能创建便签2.如何快速发送附件的邮件(网页界面) 在Safari网页界面 command ...
- 使用PullToRefreshListView时遇到Item点击事件失效问题 解决方法
最近在自己的项目中使用到了以下开源项目: https://github.com/nanchen2251/pullToRefreshDemo 相关介绍博客如下: http://www.cnblogs.c ...
- Sprint Boot 学习Q&A
[ERROR] Failed to execute goal pl.project13.maven:git-commit-id-plugin:2.1.11:revision (default) on ...
- RBM
1. 玻尔兹曼分布: $$p(E) \thicksim e^{-E/kT} $$ 2. RBM 两层:隐层和可视层, $\mathbf v$, $\mathbf h$ $$v_i \in \{0, 1 ...
- 为什么委托的减法(- 或 -=)可能出现非预期的结果?(Delegate Subtraction Has Unpredictable Result)
当我们为一个委托写 -= 的时候,ReSharper 会提示“Delegate Subtraction Has Unpredictable Result”,即“委托的减法可能出现非预期的结果”.然而在 ...