zoukankan      html  css  js  c++  java
  • swagger的使用

    @ApiImplicitParams({
    @ApiImplicitParam(name="mobile",value="手机号",required=true,paramType="form"),
    @ApiImplicitParam(name="password",value="密码",required=true,paramType="form"),
    @ApiImplicitParam(name="age",value="年龄",required=true,paramType="form",dataType="Integer")
    })
    1
    2
    3
    4
    5
    @ApiIngore:声明在方法上,标识这个方法不会显示在swagger的图形界面上。
    ApiModel:声明在实体类上。
    @ApiModelProperty:

    pom依赖需要

    <!--swagger使用的依赖-->
    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.2.2</version>
    </dependency>
    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.2.2</version>
    </dependency>
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    swagger启动需要配置一个bean


    /**
    * 配置swagger所需要的核心类
    */
    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
    //这个部分是给所有的接口方法添加一个参数,就不用每个方法单独写了
    ParameterBuilder tokenPar = new ParameterBuilder();
    List<Parameter> pars = new ArrayList<Parameter>();
    tokenPar.name("token").description("令牌")
    .modelRef(new ModelRef("string")).parameterType("query").required(false).build();
    pars.add(tokenPar.build());

    return new Docket(DocumentationType.SWAGGER_2)
    .apiInfo(apiInfo())
    .select()
    //扫描的目录,一般写到最外层就可以了
    .apis(RequestHandlerSelectors.basePackage("com.syzw.swagger.test.swagger_demo"))
    .paths(PathSelectors.any(http://www.my516.com))
    .build().globalOperationParameters(pars) ;
    }

    @SuppressWarnings("deprecation")
    private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
    .title("个人测试")
    .description("个人测试用api")
    .contact("测试")
    .version("1.0")
    .build();
    }
    }

  • 相关阅读:
    WCF ria services完美登陆功能(10)
    利用DYCOM快速建立wcf服务器端
    DYCom简要介绍
    断剑
    生命的价值
    飞翔的蜘蛛
    JSP中如何获取select标签选中的值
    wrapClass
    iconfont 在vue项目中的应用(iconcomponent组件)
    正则表达式
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11498533.html
Copyright © 2011-2022 走看看