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 ...
随机推荐
- Android程序员学WEB前端(4)-HTML(4)-注册页面-Sublime
转载请注明出处:http://blog.csdn.net/iwanghang/article/details/76576031 觉得博文有用,请点赞,请评论,请关注,谢谢!~ 注册页面1: <! ...
- 《Drools7.0.0.Final规则引擎教程》第4章 4.5RHS语法
RHS语法 使用说明 RHS是满足LHS条件之后进行后续处理部分的统称,该部分包含要执行的操作的列表信息.RHS主要用于处理结果,因此不建议在此部分再进行业务判断.如果必须要业务判断需要考虑规则设计的 ...
- [知识图谱] 环境配置:Java8 + Maven3 + HBase + Titan
1.Java Java8安装配置 2.Maven Linux下的Maven安装与配置 3.Hbase 官方安装教程:http://s3.thinkaurelius.com/docs/titan/1.0 ...
- Android MVC,MVP,MVVM模式入门——重构登陆注册功能
一 MVC模式: M:model,业务逻辑 V:view,对应布局文件 C:Controllor,对应Activity 项目框架: 代码部分: layout文件(适用于MVC和MVP两个Demo): ...
- Tensorflow 运行警告提示 Your CPU supports instructions that this TensorFlow binary was not compiled to use
由于现在神经网络这个东西比较火,准确的说是深度学习这个东西比较火,我们实验室准备靠这个东西发几个CCF A类的文章,虽然我不太懂这东西,兴趣也一般都是毕竟要跟随主流的,于是今天安装起了 Tensorf ...
- I.MX6 AD7606-4 device driver registe hacking
/********************************************************************** * I.MX6 AD7606-4 device driv ...
- RabbitMQ Study
python pika install: pip install pika Chinese rabbitmq doc: http://rabbitmq.mr-ping.com/PIKA lib doc ...
- 初次使用git遇到的问题总结
第一次使用git时,遇到好多问题,但也都是小问题,下边我把这些问题总结一下. 问题一: 创建远程仓库的时候,如果你勾选了Initialize this repository with a README ...
- mysql 随机选取一条记录
要从tablename表中随机提取一条记录,大家一般的写法就是:SELECT * FROM tablename ORDER BY RAND() LIMIT 1. 1 2 3 4 5 6 7 8 9 1 ...
- 《DSP using MATLAB》示例Example 8.23
代码: %% ------------------------------------------------------------------------ %% Output Info about ...