博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
restful
阅读量:6895 次
发布时间:2019-06-27

本文共 2124 字,大约阅读时间需要 7 分钟。

restful 大概: 

过 REST 风格体系架构,请求和响应都是基于资源表示的传输来构建的。资源是通过全局 ID 来标识的,这些 ID 一般使用的是一个统一资源标识符(URI)。 客户端应用使用 HTTP 方法(如,GET、POST、PUT 或 DELETE)来操作一个或多个资源。 通常,GET 是用于获取或列出一个或多个资源,POST 用于创建,PUT 用于更新或替换,而 DELETE 则用于删除资源。

Spring REST 支持的主要特性包括:

  • 注释,如 @RequestMapping@PathVariable,支持资源标识和 URL 映射
  • ContentNegotiatingViewResolver 支持为不同的 MIME/内容类型使用不同的表示方式
  • 使用相似的编程模型无缝地整合到原始的 MVC 层
@RequestMapping(value = "/{username}", method = RequestMethod.GET,                        headers = {"Accept=text/xml, application/json"})
public @ResponseBody        Spitter getSpitter(@PathVariable String username) {
return spitterService.getSpitter(username);        }

ContentNegotiatingViewResolver 先检查url,后检查header accept

 

HTTP message converters :可以将method返回client需要的形式,

Assuming that the Jackson JSON library is in the appli- cation’s classpath, the object returned from the handler method will be given to the MappingJacksonHttpMessageConverter for conversion into a JSON representation to be returned to the client. On the other hand, if the request header indicates that the client prefers text/xml, then Jaxb2RootElementHttpMessageConverter will be tasked with producing an XML response to the client. 

 

 关于url 解析到view:  

 

@RequestBody:发送请求的data

@RequestMapping(value = "/{username}", method = RequestMethod.PUT,                headers = "Content-Type=application/json")
@ResponseStatus(HttpStatus.NO_CONTENT)public void updateSpitter(@PathVariable String username,
@RequestBody Spitter spitter) {  spitterService.saveSpitter(spitter);

}

When the request arrives, Spring MVC will see that the updateSpitter() is able to handle the request. But the message arrives as an XML document, and this method asks for a Spitter object. In this case, the MappingJacksonHttpMessageConverter may be chosen to convert the JSON message into a Spitter object. For that to work, the following criteria must be met:

? The request’s Content-Type header must be set to application/json.

? The Jackson JSON library must be available on the application’s classpath. 

posted on
2012-12-03 15:09 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/zengyou/archive/2012/12/03/2799687.html

你可能感兴趣的文章
为何要用ERP
查看>>
Nginx之配置HTTPS站点
查看>>
STL——set
查看>>
TCP/IP中MSL详解
查看>>
JavaWeb学习总结(四十九)——简单模拟Sping MVC
查看>>
tar命令的使用
查看>>
linux环境变量,cp,mv命令,more,less,cat,tail,head,的使用
查看>>
ubuntu16.04下docker修改配置文件不生效解决办法
查看>>
CentOS7 + PHP5.6
查看>>
msyql 的半同步复制
查看>>
Tomcat7图形界面管理
查看>>
DockerCon 2017落幕:不得错过的精彩瞬间
查看>>
36.C#--方法的递归
查看>>
IO多路复用之epoll总结
查看>>
ios获取sim卡信息以及手机号码
查看>>
linux系统计时器
查看>>
C语言查漏补缺——const
查看>>
centos查看系统版本,网卡驱动和版本信息。
查看>>
14.Nginx防盗链&Nginx访问控制&Nginx解析php相关配置&Nginx代理
查看>>
Linux-Apache默认虚拟主机
查看>>