spring boot2集成api文档工具swagger-ui(下)

…衆ロ難τιáo~ 提交于 2020-02-26 16:30:25

接上篇

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!