zoukankan      html  css  js  c++  java
  • Spring boot添加Swagger配置


    导入Swagger

    Gradle

      dependencies{

      compile('io.springfox:springfox-swagger2:2.8.0')
      compile('io.springfox:springfox-swagger-ui:2.8.0')
      compile 'io.swagger:swagger-jersey2-jaxrs:1.5.8'
      compile('com.mangofactory:swagger-springmvc:1.0.2')
      compile('com.mangofactory:swagger-models:1.0.2')
      compile('com.wordnik:swagger-annotations:1.3.11')*
      }

    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
      @Bean
      public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
          .select()
    
          .protocols(new HashSer<String>(Lists.newArrayList("http")))
          .apis(RequestHandlerSelectors.basePackage("com.arthur.demo.controller"))----->对应控制层的API接口层包路径
          .paths(PathSelectors.any())
          .pathMapping("/")
          .build()
          .apiInfo(apiInfo());
      }
      @Bean
    public UiConfiguration uiConfig(){
      return UiConfiguration.DEFAULT;
      }
      private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
          .title("API Title")
          .description("API接口说明文档")
          .termsOfServiceUrl(" API terms of service")
          .version("1.0")
          .build();
      }
    }

    Swagger注解

     

    举例说明

    @RestController
    @Api(value="获取邮箱地址",description = "getEmail(外层显示)",produces=MediaType.APPLICATION_FROM_URLENCODED_VALUE)
    public class LoginController {
    
    @ApiOperation("用户登陆", notes = "通过该接口获取激活邮箱信息", httpMethod = "POST", produces = MediaType.APPLICATION_FROM_URLENCODED_VALUE)
    @PostMapping(value = "/login")
    public ResponseEntity Login(@ApiParam(value = "环境", required = true) @RequestParam(value = "baseurl", required = true) String baseurl
    , @ApiParam(value = "账号", required = true) @RequestParam(value = "userName", required = true) String userName) {
    return baseurl,userName;
    }
    }
  • 相关阅读:
    为什么要用do-while(0)?
    网络字节序&大小端存储
    sql语句w3school教程
    C++编码规范
    std::deque双端队列介绍
    gdb基本操作
    gdb调试多线程
    数据库基础
    删除vector所有元素
    stl迭代器失效
  • 原文地址:https://www.cnblogs.com/Byronlyu/p/9804205.html
Copyright © 2011-2022 走看看