SpringBoot_restful
来源:互联网 发布:网站发布到域名 编辑:程序博客网 时间:2024/05/29 20:00
1. HTTP知识
HTTP具体介绍
2. restful ?
最近学习了一下restful风格,简而言之,就是一种接口访问方式+命名的规范。
具体一点, GET用来获取资源,POST用来新建资源(也可以用于更新资源),PUT用来更新资源,DELETE用来删除资源。
牛人总结restful :
(1)每一个URI代表一种资源;
(2)客户端和服务器之间,传递这种资源的某种表现层;
(3)客户端通过四个HTTP动词,对服务器端资源进行操作,实现”表现层状态转化”。
原文
3.代码demo
- 查询单个对象(GET + 路径传参)
@RequestMapping(value = "/city/{id}",method = RequestMethod.GET) public BaseResp<City> getCity(@PathVariable Long id){ return new BaseResp(ResultStatus.SUCCESS,restfulService.getCity(id)); }
- 查询列表(GET)
@RequestMapping(value = "/city",method = RequestMethod.GET) public BaseResp<List<City>> getCity(){ return new BaseResp(ResultStatus.SUCCESS,restfulService.listCity()); }
- 查询分页(GET)
@RequestMapping(value = "/city/{pages}/{size}",method = RequestMethod.GET) public BaseResp<Page<City>> getCity(@PathVariable Integer pages, @PathVariable Integer size){ return new BaseResp(ResultStatus.SUCCESS,restfulService.listCity(pages, size)); }
- 保存对象(POST)
@RequestMapping(value = "/city",method = RequestMethod.POST) public BaseResp<City> saveCity(@RequestBody City city){ return new BaseResp(ResultStatus.SUCCESS,restfulService.saveCity(city)); }
- 修改对象(PUT)
@RequestMapping(value = "/city/{id}",method = RequestMethod.PUT) public BaseResp<Integer> saveCity(@PathVariable Long id, @RequestBody City city){ return new BaseResp(ResultStatus.SUCCESS,restfulService.updateCity(id,city)); }
- 删除(DELETE)
@RequestMapping(value = "/city/{id}",method = RequestMethod.DELETE) public BaseResp<String> deleteCity(@PathVariable Long id){ restfulService.deleteCity(id); return new BaseResp(ResultStatus.SUCCESS); }
- 上传文件demo
@RequestMapping(value = "/upload/{typeId}") public BaseResp<String> uploadFile(@PathVariable Integer typeId, @RequestParam("file") MultipartFile file){ if (null != file){ System.out.println(typeId); System.out.println(file.getOriginalFilename()); } return new BaseResp(ResultStatus.SUCCESS); }
阅读全文
0 0
- SpringBoot_restful
- 安装CherryTree,报错无法找到 gtksourceview2
- 2017多校六 1002题 hdu 6097 Mindis 相似三角形 计算几何
- 【Codeforces 608B】Hamming Distance Sum(前缀和)
- 2.Android灯光系统_编写HAL_lights.c
- java异常简介及架构
- SpringBoot_restful
- 数据库基础知识
- VideoView视频大小屏切换/缓冲/卡顿监听和处理
- 回文寻找
- 基于docker的codis3部署
- leetcode
- 《笨办法学python》加分习题7——我的答案
- 基本数据类型
- Windows下MySql错误代码1045的解决方法