Springboot集成SwaggerUI

废话不说 直接分析

  1. 什么是SwaggerUI?参考 https://www.cnblogs.com/JoiT/p/6378086.html
    Swagger能成为最受欢迎的REST APIs文档生成工具之一,有以下几个原因:

    Swagger 可以生成一个具有互动性的API控制台,开发者可以用来快速学习和尝试API。
    Swagger 可以生成客户端SDK代码用于各种不同的平台上的实现。
    Swagger 文件可以在许多不同的平台上从代码注释中自动生成。
    Swagger 有一个强大的社区,里面有许多强悍的贡献者

2、搭建一个SpringBoot 案例 集成SwaggerUI 导入对应Maven pom.xml

		<dependency>
		       <groupId>io.springfox</groupId>
		       <artifactId>springfox-swagger2</artifactId>
		       <version>2.6.0</version>
		</dependency>
		<dependency>
        <groupId>io.springfox </groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.6.0</version>
    </dependency>

3、编写Swagger 加载配置类

package com.api.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 
 * @ClassName:  Swagger2Config   
 * @Description:TODO(swagger 配置)   
 * @author: drj 
 * @date:   2019年1月19日 下午8:10:52   
 *     
 * @Copyright: 2019 
 *
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {
	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors.basePackage("com.api")).paths(PathSelectors.any())
				.build();
	}//PathSelectors.regex("/v1/")

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("dairuijie Restful API").description("代瑞杰 API")
				.version("1.0").build();

	}
}

4、启动项目,浏览器输入 http://127.0.0.1:8888/swagger-ui.html# 自己的项目ip+port 如图:
在这里插入图片描述
5、git 项目地址 https://github.com/dairuijie/api.git 有具体注解 使用demo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蜗牛乌龟一起走

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值