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;
    }
    }
  • 相关阅读:
    JavaScript使用方法和技巧大全
    PHP JSON 数据解析代码
    效率较高的php下读取文本文件的代码
    PHP操作MongoDB 数据库
    安装mongo php拓展
    MongoDB与MySQL的插入、查询性能测试
    java字符数组char[]和字符串String之间的转换
    python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件
    python操作txt文件中数据教程[2]-python提取txt文件
    python操作txt文件中数据教程[1]-使用python读写txt文件
  • 原文地址:https://www.cnblogs.com/Byronlyu/p/9804205.html
Copyright © 2011-2022 走看看