Springboot集成Restful风格《SpringBoot学习六》

版权声明:本文为HCG原创文章,未经博主允许不得转载。请联系[email protected] https://blog.csdn.net/qq_39455116/article/details/83744686

1. restful介绍

REST:英文representational state transfer直译为表现层状态转移,或者表述性状态转移;Rest是web服务的一种架构风格,一种设计风格,是一种思想;同时Rest不是针对某一种编程语言的。
以webService为例通俗解释。
非Rest设计,以往我们都会这么写:
http://localhost:8080/admin/getUser (查询用户)
http://localhost:8080/admin/addUser (新增用户)
http://localhost:8080/admin/updateUser (更新用户)
http://localhost:8080/admin/deleteUser (删除用户)
总结:以不同的URL(主要为使用动词)进行不同的操作。

Rest架构:
GET http://localhost:8080/admin/user (查询用户)
POST http://localhost:8080/admin/user (新增用户)
PUT http://localhost:8080/admin/user (更新用户)
DELETE http://localhost:8080/admin/user (删除用户)
总结:URL只指定资源,以HTTP方法动词进行不同的操作。用HTTP STATUS/CODE定义操作结果。

Restful:遵守了rest风格的web服务便可称为Restful。

2. 重点:

在之前SpringBoot学习系列的工程基础上,添加Restful API。Restful的核心在controller

这里介绍一个新的注解
@RestController作用相当于@ResponseBody + @Controller 
这里的在线API工具使用的是SpringBoot学习(六)中介绍的swagger,
@ApiOperation为swagger中的注解。

代码就不写了,其实不用@RestController和API也能在原来的项目中实现restful风格

猜你喜欢

转载自blog.csdn.net/qq_39455116/article/details/83744686