zoukankan      html  css  js  c++  java
  • swagger配置

    1.pom.xml

    <!--swagger2-->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>2.6.1</version>
                <exclusions>
                    <exclusion>
                        <groupId>io.swagger</groupId>
                        <artifactId>swagger-annotations</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    <!--下面的不添加会导致访问报404-->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>2.6.1</version>
            </dependency>
    <!--swagger2密码-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </dependency>
    application.properties添加swagger访问密码:
    
    security.basic.enabled=true
    security.basic.path=/swagger-ui.html
    security.user.name=admin
    security.user.password=123456

    2.swagger配置类

    参考:http://blog.didispace.com/springbootswagger2/

    3.生成离线文档:

    使用springfox-staticdocs生成swagger离线api文档附带源码

    4.项目使用demo:

    responseMessages.add(new ResponseMessageBuilder().code(999).message("未知异常").responseModel(new ModelRef(error)).build());
    return
          new Docket(DocumentationType.SWAGGER_2).
                          apiInfo(buildApiInfo())
                          .tags(new Tag("tag1", "接口类描述1"),
                                  new Tag("tag2", "接口类描述2")).
                          select().
                          apis(RequestHandlerSelectors.
                                  basePackage(swaggerBasePackage)).
                          paths(PathSelectors.any()).
                          build()
                          .useDefaultResponseMessages(false)
                          .globalResponseMessage(RequestMethod.GET, responseMessages)
    @Api(tags = {"tag1"})
    @RestController
    @RequestMapping(value = "test")
    public class ResourceApi {
    
        //...some code...
    
        /**
         * @author Jill
         */
        @PostMapping
        @ApiOperation("查询资源列表接口")
        public Response<Object> getInfoList(@RequestBody @Valid
                                                @ApiParam(name = "查询条件", value = "查询条件")
                                                        SearchVO vo) {
  • 相关阅读:
    用例要素(非原创)
    边界接口设计
    项目管理平台架构
    内外网邮件自动转发
    Python技术公众号100天了
    将博客搬至CSDN
    Android项目真的要去做混淆(加密)处理
    【转】Android Gson的使用
    【转】在eclipse上使用Git
    在AChartEngine上绘图,手指标记当前位置
  • 原文地址:https://www.cnblogs.com/goingforward/p/10388412.html
Copyright © 2011-2022 走看看