swagger使用详解

springBoot swagger Configuration配置

@Configuration
public class SwaggerConfigure {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yspay.insurance.online.controller")) //指向你的controller包
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("测试系统")//这个会在Swagger页面中显示,
                .description("服务")
                .termsOfServiceUrl("http://localhost:7000/insurance")
                .version("2.0")
                .build();
    }
}

maven -

<!-- 接口说明文档 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
        </dependency>

 

 

类 级别注解:

@Api

属性:tags-类的说明,description-覆盖类名

@ApiIgnore 隐藏接口,方法,参数

方法级别注解

@ApiImplicitParams({@ApiImplicitParam(name = "<参数名称>", value = "参数说明", required = true, paramType="body")})

paramType 值:
       header-->放在请求头。请求参数的获取:@RequestHeader(代码中接收注解)
       query-->用于get请求的参数拼接。请求参数的获取:@RequestParam(代码中接收注解)
       path(用于restful接口)-->请求参数的获取:@PathVariable(代码中接收注解)
       body-->放在请求体。请求参数的获取:@RequestBody(代码中接收注解)
       form(不常用)
@ApiOperation(value = "创建订单") 方法说明

@ApiParam(value="参数说明",name="参数名",对应方法参数)

实体类注解

第一步,在实体类中@ApiModel(description= “描述”)
第二步,在字段属性中@ApiModelProperty(value = “字段备注”)

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值