Knife4j接口文档

pom

        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-spring-boot-starter</artifactId>
            <version>2.0.9</version>
        </dependency>

配置文件

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

配置类中

// 配置类上标注
@EnableSwagger2WebMvc

    @Bean
    public Docket dockerBean() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("invoicing")
                        .description("# invoicing 接口文档")
                        .version("1.0")
                        .contact(new Contact("hhx","person_website","xxxx@qq.com"))
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.guet.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

如果配置的有SpringSecurity,进行放行资源

           .antMatchers("/doc.html",
                   "/v2/api-docs-ext/**",
                   "/favicon.ico",
                   "/webjars/**",
                   "/img.icons/**",
                   "/swagger-resources/**",
                   "/v2/api-docs/**",
                   "/swagger-ui/**"
           ).permitAll()

一些注解的作用

@Api:用于标注Controller,主要是对该Controller下的接口,进行一个总体的描述,如xxxx模块。
@ApiOperation:用在Controller方法上,说明该接口的作用
@ApiImplicitParam:用在@ApiImplicitParams注解中,也可以单独使用,说明一个请求参数的是否必传,参数含义,类型等等
@ApiParam:写在方法参数前面。用于对参数进行描述或说明是否为必添项等说明。
swagger常用注解
wagger信息配置与常用注解

@RequestParam的required参数为true的含义是:接口参数名一定要存在,但参数后面有没有值它不管

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值