zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    WebActivatorEx
    autofac
    svn: E230001: Server SSL certificate verification failed
    uml 关系
    PowerDesigner生成PHP代码 UML
    linux 命令
    jQuery ajax跨域调用出现No Transport
    2015年终总结
    php+apache配置
    Memcached
  • 原文地址:https://www.cnblogs.com/qinshengfei/p/12188387.html
Copyright © 2011-2022 走看看