springBoot简单集成swagger

2020-05-11 19:04:58  卢浮宫  版权声明:本文为站长原创文章,转载请写明出处


一、背景

    最近做前后端分离,新的api接口需要调试,于是乎就简单集成了一下swagger


二、swagger支持

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


三、swagger配置

       
        import io.swagger.annotations.ApiOperation;
        import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
* @author XA
* date 2020/5/9 20:49
* description Swagger配置类
* params
* return
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket swaggerSpringMvcPlugin() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).build();
}

}

四、项目中使用

       1、在控制类中使用注解

        @Api(description = "用户角色权限接口")

  2、在控制类方法中使用注解

    



更多精彩请关注guangmuhua.com


最新评论:

a
2020-05-19 17:14:03
1楼
祝贺nuxt上线
2020-05-14 21:11:32
2楼