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 ...
随机推荐
- leetCode之Median of Two Sorted Arrays
[题目描述] There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of ...
- 关于命名空间namespace
虽然任意合法的PHP代码都可以包含在命名空间中,但只有以下类型的代码受命名空间的影响,它们是:类(包括抽象类和traits).接口.函数和常量. 在声明命名空间之前唯一合法的代码是用于定义源文件编码方 ...
- 《Drools7.0.0.Final规则引擎教程》第4章 4.9 关键字
关键字 从Drools 5开始引入了硬关键字和软关键字.硬关键字是保留关键字,在命名demo对象,属性,方法,函数和规则文本中使用的其他元素时,不能使用任何硬关键字.以下是必须避免的硬关键字: (1) ...
- 开源一款ftp软件——filezilla
filezilla是一款高性能ftp/sftp文件工具,关于它的具体的介绍可参见其官网:https://www.filezilla.cn/.其原作者是Tim Kosse (tim.kosse@file ...
- ios图标生成器网址 插件禁用后,可以选择这个
1. 可以使用在线移动图标生成工具:图标工场http://icon.wuruihong.com/网站自动生成iOS所需的所有对应格式的图标 2. 如果直接选择iOS,会自动生成29pt.40pt.50 ...
- rabbitMQ高可用
镜像模式 镜像模式和普通模式的区别就是,队列的数据都镜像了一份到所有的节点上.这样任何一个节点失效,不会影响整个集群的使用. 在实现上,mirror queue内部有一套选举算法,会选出一个maste ...
- fedora26 Mysql 开放远程链接服务
下载安装MySQL 用以下指令安装 $ dnf install mysql-server 注意:Fedora默认安装mariadb 安装完成之后,用以下指令测试 $ mysql --version 开 ...
- 【sklearn】from sklearn.extermals import joblib(保存模型和加载模型)
原创博文,转载请注明出处! sklearn中保存和加载模型的方法 1.载入模块 from sklearn.externals joblib. model = joblib. # -*- coding: ...
- 模仿python中的range功能
主要是利用生成器来写的一个函数: def myxrange(start, stop = None, step = 1): #这里的stop一定要等于None,不能等于0,要不然会有好多问题 if st ...
- Ubuntu 16.04安装QQ国际版
QQ国际版wine-qqintl的下载链接:http://pan.baidu.com/s/1jIwKdXs sudo apt install libgtk2.0-0:i386 sudo apt in ...