spring boot2集成api文档工具swagger-ui(下)
接上篇
swaggerUI提供了可视化界面帮助我们管理服务的访问路口,这就需要我们在代码中规范我们的书写格式。并且在swagger的界面上还能够模拟浏览器对服务进行访问。
接口总览
创建POST接口
- 创建一个保存用户的接口
@RequestMapping(value = "/addUser",method = RequestMethod.POST) @ApiModelProperty(value="user",notes = "用户信息的json串") @ApiOperation(value = "新增用户", notes="返回新增的用户信息") public Object adduser(@RequestBody User user){ Map map = new HashMap(); map.put("msg","success"); map.put("code","1"); return map; }
创建一个PUT接口
- 修改用户接口
@RequestMapping(value = "/updateUser",method = RequestMethod.PUT) @ResponseBody @ApiModelProperty(value="user",notes = "修改后用户信息的json串") @ApiOperation(value = "更新用户信息", notes="返回更新的用户信息") public Map<String,Object> updateUser(@RequestBody User user) { Map map = new HashMap(); map.put("msg","success"); map.put("code","1"); return map; }
创建一个GET接口
- 创建获取用户信息的接口
@RequestMapping(value = "/byname", method = RequestMethod.GET) @ResponseBody @ApiImplicitParam(paramType = "query",name= "username" ,value = "用户名",dataType = "string") @ApiOperation(value = "通过用户名获取用户信息", notes="返回用户信息") public Object byname(@RequestParam @ApiParam(name="username",value="名字",required = true)String username) { Map map = new HashMap(); map.put("msg","success"); map.put("code","1"); return map; }
创建一个DELETE接口
@RequestMapping(value = "/deleteUser", method = RequestMethod.DELETE) @ResponseBody @ApiOperation(value = "通过id删除用户信息", notes="返回删除状态1 成功 0 失败") public Map<String,Object> deleteUser(@RequestParam @ApiParam(name="id",value="id",required = true) Integer id) { Map map = new HashMap(); map.put("msg","success"); map.put("code","1"); return map; }
总结
本文项目代码地址:
https://gitee.com/Qinux/springboot_swaggerui
相关推荐
lxhuang 2020-11-03
ChinaJoeEE 2020-08-16
Luckyunyun 2020-08-15
bapinggaitianli 2020-08-07
phpboy 2020-07-19
染血白衣 2020-11-16
SAMXIE 2020-11-04
一个智障 2020-11-15
学习web前端 2020-11-09
yiranpiaoluo 2020-11-04
88274956 2020-11-03
82387067 2020-11-03
huangliuyu00 2020-10-29
sichenglain 2020-10-27
Dayer 2020-10-27
小马的学习笔记 2020-10-23
liuweiITlove 2020-10-14
kjyiyi 2020-10-10
fanjunjaden 2020-10-09