Swagger2使用

Swagger2文档API

为了减少程序员撰写文档时间,提高生产力,Swagger2应运而生,使用Swagger2可以减少编写过多的文档,只需要通过代码就能生成文档API,提供给前端人员对接,非常方便。

引入依赖

<!-- swagger2 配置 --> 
<dependency> 
<groupId>io.springfox</groupId> 
<artifactId>springfox-swagger2</artifactId> 
<version>2.4.0</version> 
</dependency>
 <dependency> 
 <groupId>io.springfox</groupId> 
 <artifactId>springfox-swagger-ui</artifactId>
  <version>2.4.0</version> </dependency>
   <dependency> 
   <groupId>com.github.xiaoymin</groupId> 
   <artifactId>swagger-bootstrap-ui</artifactId> 
   <version>1.6</version>
 </dependency>

设置跨域访问

@Configuration
@EnableSwagger2
public class Swigger2 {
    //配置swagger2核心配置
    @Bean
    public Docket creakRestApi() {
        return new Docket(DocumentationType.SWAGGER_2) //指定api类型为swigger2
                .apiInfo(this.apiInfo())//指定api类型为swigger2
                .select()
                .apis(RequestHandlerSelectors
                        .basePackage("com.dada.controller")) //指定controller
                .paths(PathSelectors.any()) //地址下的所有(any)
                .build();
    }
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("哒哒网电商平台接口api")//标题
                .contact(new Contact("小马哒哒哒","http://dadawang.xyz","984501240@qq.com"))//联系人信息
                .description("专为哒哒网提供的api文档") //详细信息
                .version("1.0.1")
                .termsOfServiceUrl("http://www.dadawang.xyz")
                .build();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值