swagger2 隐藏model,添加文字说明 ,swagger 2.9.2

添加maven pom依赖

		
			io.springfox
			springfox-swagger2
			2.9.2
		

两个重要注解 @ApiModel,@ApiModelProperty

@ApiModel 用在class类上,对类解释,如:  @ApiModel(value = "订单")

@ApiModelProperty 顾名思义指的是model的属性,用在属性上,如:@ApiModelProperty(value = "订单号id(不需要传)",readOnly = true),

其中@ApiModelProperty 中的标签readOnly(表示是否只读 若为true,则是不会显示在swagger-ui的实体上,默认false),required(表示是否必传,若为true表示必传,默认为false)

eg:

package xx.xx.xx.xx.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;



import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
*  
* @author zsigner
*/
@ApiModel(value = "订单")
public class RepairsOrder implements Serializable {

    private static final long serialVersionUID = -2729271700842553073L;
    /**
    * 订单号id
    */
    @ApiModelProperty(value = "订单号id(不需要传)",readOnly = true)
    private Integer orderId;

    /**
    * 订单号
    */
    @ApiModelProperty(value = "订单编号号(不需要传)",readOnly = true)
    private Long orderNumber;

    
    /**
    * 品牌id
    */
    @ApiModelProperty(value = "品牌id",required = true)
    private Integer brandId;

    


    public RepairsOrder() {
    }

    public Integer getOrderId() {
        return orderId;
    }

    public void setOrderId(Integer orderId) {
        this.orderId = orderId;
    }

    public Long getOrderNumber() {
        return orderNumber == null ? System.currentTimeMillis() : orderNumber;
    }

    public void setOrderNumber(Long orderNumber) {
        this.orderNumber = orderNumber;
    }


    public Integer getBrandId() {
        return brandId;
    }

    public void setBrandId(Integer brandId) {
        this.brandId = brandId;
    }

}

Controller:

@ApiOperation(value = "提交订单接口", notes = "提交订单接口")
    @RequestMapping(value = "add",method = RequestMethod.POST)
    public void add(@RequestBody RepairsOrder repairsOrder){

        .....;
    }

结果如图:

swagger2 隐藏model,添加文字说明 ,swagger 2.9.2_第1张图片

swagger2 隐藏model,添加文字说明 ,swagger 2.9.2_第2张图片

 

你可能感兴趣的:(SWAGGER)