美文网首页
swagger2笔记

swagger2笔记

作者: 我是电饭煲 | 来源:发表于2020-03-30 19:44 被阅读0次

swagger2搭建

  • 引入
<!-- swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>26.0-jre</version>
        </dependency>
  • 配置
/**
 * Swagger2 配置类
 * @author yuanfeng.z
 * @date 2019/11/25 16:28
 */
@EnableSwagger2
@Configuration
public class Swagger2Config {
    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()// 指定需要展现的api接口
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class)) // 扫描接口
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfo("用户服务",
                "用户服务",
                "v0.0.1",
                "",
                null,
                "",
                "",
                new ArrayList<>());
    }
}
  • 描述类
@Api(tags = "会员管理")
  • 描述接口
@ApiOperation(value = "register", notes = "注册", httpMethod = "POST")

https://blog.csdn.net/liuchuanhong1/article/details/59064794
https://blog.csdn.net/liuchuanhong1/article/details/58594045

相关文章

网友评论

      本文标题:swagger2笔记

      本文链接:https://www.haomeiwen.com/subject/ohijwctx.html