加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

RESTful API设计规范

发布时间:2020-12-14 02:03:05 所属栏目:百科 来源:网络整理
导读:HTTP方法 URI 方法名 参数 示例 备注 GET /resource index @RequestMapping() @ResponseBody Public Result index(Domain condition) 显示所有资源 GET /resource/1 show Id=1 @RequestMapping(path=”{id}”) @ResponseBody public Result show(@PathVariab

HTTP方法

URI

方法名

参数

示例

备注

GET

/resource

index

@RequestMapping()

@ResponseBody

Public Result index(Domain condition)

显示所有资源

GET

/resource/1

show

Id=1

@RequestMapping(path=”{id}”)

@ResponseBody

public Result show(@PathVariable Long id)

显示单个资源

GET

/resource/1/edit

edit

Id=1

@RequestMapping(path=”{id}/edit”)

@ResponseBody

public Domain edit(@PathVariable Long id);

编辑单个资源

GET

/resource/new

editNew

@RequestMapping(path=”new”);

public String editNew();

新建

POST

/resource

create

@RequestMapping(method=RequestMethod.POST);

@ResponseBody

public Result create(Domain domain);

创建单个资源

PUT

/resource/1

update

Id=1

@RequestMapping(path=”{id}”,method=RequestMethod.UPDATE);

@ResponseBody

public Result update(@PathVariable Long id);

更新单个资源

DELETE

/resource/1

destroy

Id=1

@RequestMapping(path=”{id}”,method=RequestMethod.DELETE);

@ResponseBody

public Result destroy(@PathVariable Long id);

删除单个资源

POST

/resource/batch/create

batchCreate

@RequestMapping(path=”batch/create”,method=RequestMethod.POST);

@ResponseBody

public Result batchCreate(List<Domain> domains);

创建多个资源

POST

/resource/batch/update

batchUpdate

@RequestMapping(path=”batch/update”,method=RequestMethod.POST);

public Result

@ResponseBody

batchUpdate(List<Domain> domains);

更新多个资源

POST

/resource/batch/destroy

batchDestroy

@RequestMapping(path=”batch/destroy”,method=RequestMethod.POST);

@ResponseBody

public Result batchDestroy(List<Domain> domains);

删除多个资源

POST/GET

/resource/action

action

@RequestMapping(path=”action”);

@ResponseBody

public Result action(参数);

对资源的其他操作

说明:

1.resource代表对服务器请求的资源,比如进件,客户资料,发标信息等等

2.action代表除crud外的操作,命名尽量见文知意

3.标蓝色的对于SPA来说可能不需要,如果是传统的web页面则需要

4.参数只列出了url中的,表单中的未在上表格中体现

5.Domain泛指各种实体,写具体接口要以具体实体类替换

6.Result有两种含义,一种是泛指返回的结果类型,可以是各种实体或实体集合等等,另外一种是指结果的封装,即Result中封装Message对象与实体对象,Message对象提供处理结果与消息,实体对象作为展示数据,这里推荐第二种方式

有好的意见,请大家提出来,谢谢。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读