swagger注释@API详细说明

Swagger是当前最好用的Restful API文档生成的开源项目,通过swagger-spring项目

实现了与SpingMVC框架的无缝集成功能,方便生成spring restful风格的接口文档,

同时swagger-ui还可以测试spring restful风格的接口功能。

官方网站为:http://swagger.io/

中文网站:http://www.sosoapi.com

汇总

作用范围 API 使用位置
对象属性 @ApiModelProperty 用在参数对象的字段上
协议集描述 @Api 用于controller类上
协议描述 @ApiOperation 用在controller的方法上
Response集 @ApiResponses 用在controller的方法上
Response @ApiResponse 用在 @ApiResponses里边
非对象参数集 @ApiImplicitParams 用在controller的方法上
非对象参数描述 @ApiImplicitParam 用在@ApiImplicitParams的方法里边
描述返回对象的意义 @ApiModel 用在返回对象类上

@ApiModelProperty的用法   


value–字段说明 
name–重写属性名字 
dataType–重写属性类型 
required–是否必填 
example–举例说明 
hidden–隐藏

扫描二维码关注公众号,回复: 1439091 查看本文章

//  我这个用在实体类的get()方法上了
/**
     * 获取城市编号
     * @return 城市编号
     */
    @ApiModelProperty(value="城市编号",example="058",required=true)
    public String getCode() {
        return code;
    }

    /**
     * 设置城市编号
     * @param code  城市编号
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * 获取城市名称
     * @return 城市名称
     */
    @ApiModelProperty(value="城市名称",example="guangZhou",required=true)
    public String getName() {
        return name;
    }
 

@Api

value - 字段说明

description - 注释说明这个类

@ApiOperation

value - 字段说明

notes - 注释说明

httpMethod - 说明这个方法被请求的方式

response - 方法的返回值的类型

 

@ApiResponse

code - 响应的HTTP状态码

message - 响应的信息内容

知道的也就这么点了    有谁了解清楚的  给个补充呗 !  

猜你喜欢

转载自my.oschina.net/u/3709014/blog/1791116