Giter VIP home page Giter VIP logo

demo-swagger2's Introduction

说明

技术说明

  • springboot 项目结构
  • swagger2 在线接口文档/支持markdown/confluence/html/json 格式接口文档下载
  • 通过aop方式整合swagger2接口注解, 使用swagger2定义的接口自动记录操作日志

项目中使用

@Api(value = "/users", tags = "用户操作接口")
@RestController
@RequestMapping(value="/users")     
public class UserController {

    static Map<Long, User> users = Collections.synchronizedMap(new HashMap<Long, User>());

    @ApiOperation(value="获取用户列表", notes="")
    @RequestMapping(value={""}, method=RequestMethod.GET)
    public List<User> getUserList() {
        List<User> r = new ArrayList<User>(users.values());
        return r;
    }

    @ApiOperation(value="创建用户", notes="根据User对象创建用户")
    @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
    @RequestMapping(value="", method=RequestMethod.POST)
    public String postUser(@RequestBody User user) {
        users.put(user.getId(), user);
        return "success";
    }
}

启动

运行: hello.Application

快速尝试

  1. 模拟登入(模拟登入后才能记录日志)
http://localhost:8080/login?name=User
  1. 访问接口在线文档(接口信息,可在页面直接请求测试接口,后台将自动记录操作日志可保存入库)

格式:http://host:port/xxx/swagger-ui.html

http://localhost:8080/swagger-ui.html

模拟登入后,选择不同接口测试,输入请求参数,点击"Try it out",后台模拟入库对应操作日志。

  1. 接口的swagger描述信息json格式,用于导入mock系统

http://{主机地址}:{服务启动端口}/xxx/v2/api-docs?group={需要生成的api所属组name}

http://localhost:8080/v2/api-docs?group=default
  1. 支持多种格式接口文档下载,用于项目管理及前后端联调使用
http://localhost:8080/swagger/markdown
http://localhost:8080/swagger/confluence
http://localhost:8080/swagger/asciidoc
http://localhost:8080/swagger/json
http://localhost:8080/swagger/html

相关文档

  1. springboot/springmvc实现swagger2/及国际化

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.