spring boot集成swagger2.x

1.引入依赖配置

  <!--集成SWAGGER-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.7.0</version>
        </dependency>

2.添加配置config

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                // 分组
                .groupName("main")
                .select()
                // api的包路径
                .apis(RequestHandlerSelectors.basePackage("com.xiaoyoung"))
                .paths(PathSelectors.any()).build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 文档标题
                .title("API Doc")
                // 文档描述
                .description("接口描述")
                // 版本号
                .version("1.0")
                .build();
    }
}

3.配置适配路径,否则会报错

#配置swagger
spring.mvc.pathmatch.matching-strategy=ant_path_matcher

4.添加swagger注解

4.1、类注解

注解说明
@Api对请求类的说明

4.2、方法注解

注解说明
@ApiOperation方法的说明
@ApiImplicitParams方法参数的说明;
@ApiImplicitParam用于指定单个参数的说明。

4.3、方法的响应状态的描述

注解说明
@ApiResponses方法返回值的说明 ;
@ApiResponse用于指定单个参数的说明。

4.4、对象的描述

注解说明
@ApiModel用在JavaBean类上,说明JavaBean的 整体用途
@ApiModelProperty用在JavaBean类的属性上面,说明此属性的的含议

效果图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值