Swagger

时间:2021-06-18 20:07:05   收藏:0   阅读:0

1.简介

RestFul API文档在线自动生成工具 => API文档与API定义同步更新

直接运行,可以在线测试API接口

2.在项目使用Swagger需要springfox

3.SpringBoot集成Swagger2

在pom.xml中导入依赖

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>

  

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
</dependency>

4.编写一个Hello过程

package com.kuang.swagger.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController { 
    
    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }
}

5.配置swagger ==》config

config/SwaggerConfig.java

package com.kuang.swagger.config;

import springfox.documentation.swagger2.annotations.EnableSwagger2;

import org.springframework.context.annotation.Configuration;

@Configuration
@EnableSwagger2  // 开启swagger2
public class SwaggerConfig {

}

  技术图片

 6.启动运行

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

技术图片

 

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!