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 ...
随机推荐
- 6个变态的C语言程序
转载自 陈浩 coolshell.cn 下面的六个程序片段主要完成这些事情: 输出Hello, World 混乱C语言的源代码 下面的所有程序都可以在GCC下编译通过,只有最后一个需要动用C++的编译 ...
- Linux下常用压缩、解压缩命令
常用的压缩工具 一是单纯的单文件压缩工具,主要有compress,gzip,bzip2. 二是打包压缩工具,也是最常用的,tar 压缩比:compress<gzip<bzip2 co ...
- 使用lets encrypt证书加密
1 git clone https://github.com/letsencrypt/letsencrypt 2 ./letsencrypt-auto certonly -d 域名
- SpringMVC札集(07)——JSON数据
自定义View系列教程00–推翻自己和过往,重学自定义View 自定义View系列教程01–常用工具介绍 自定义View系列教程02–onMeasure源码详尽分析 自定义View系列教程03–onL ...
- TF随笔-10
#!/usr/bin/env python# -*- coding: utf-8 -*-import tensorflow as tf x = tf.constant(2)y = tf.constan ...
- HAWQ + MADlib 玩转数据挖掘之(一)——安装
一.MADlib简介 MADlib是Pivotal公司与伯克利大学合作的一个开源机器学习库,提供了精确的数据并行实现.统计和机器学习方法对结构化和非结构化数据进行分析,主要目的是扩展数据库的分析能力, ...
- UNIX环境高级编程 标准IO库
标准I/O库处理很多细节,使得便于用户使用. 流和 FILE 对象 对于标准I/O库,操作是围绕 流(stream)进行的.当用标准I/O打开或创建一个文件时,我们已使一个流与一个文件相关联. 对于A ...
- 搭建Hadoop2.6.0+Eclipse开发调试环境(以及log4j.properties的配置)
上一篇在win7虚拟机下搭建了hadoop2.6.0伪分布式环境.为了开发调试方便,本文介绍在eclipse下搭建开发环境,连接和提交任务到hadoop集群. 1. 环境 Eclipse版本Luna ...
- LeetCode 549. Binary Tree Longest Consecutive Sequence II
原题链接在这里:https://leetcode.com/problems/binary-tree-longest-consecutive-sequence-ii/description/ 题目: G ...
- 随着tomcat一起启动一个线程
package test; import javax.servlet.*; public class MyCode implements ServletContextListener { //当Tom ...