Swagger学习

在SpringBoot中搭建Swagger文档1.导包Maven依赖如下,版本自选(现在是2.9.2版本): <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency> <groupId>io.spr...
摘要由CSDN通过智能技术生成

在SpringBoot中搭建Swagger文档

1.导包

Maven依赖如下,版本自选(现在是2.9.2版本):

 <!-- 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>

在项目中设置配置类

@Configuration
// 开启Swagger2的自动配置
@EnableSwagger2
public class SwaggerConfig {
}

配置Swagger实例

Swagger实例Bean是Docket,所以通过配置Docket实例来配置Swaggger。

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket docket(){
     // 配置docket以配置Swagger具体参数
        return new Docket(DocumentationType.SWAGGER_2);
    }
}

配置好了启动项目
访问 http://localhost:8080/swagger-ui.html
在这里插入图片描述

配置API文档的信息

通过apiInfo()属性配置文档信息:

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
    }
    private ApiInfo apiInfo(){
        Contact contact =new Contact("联系人名字","联系人名字访问链接","联系人邮箱");

        return new ApiInfo("Swagger学习文档", //标题	
                "这是学习swagger生成的文档",		//描述
                "v1.0",												//版本
                "http::localhost:8080",						//"http://terms.service.url/组织链接", 组织链接
                contact,											// 联系人信息
                "pach 2.0 许可",								 // 许可
                "许可链接",				
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值