Swagger ApiModelProperty 不起作用

Đỗ *_*Hòa 7 java swagger

@ApiModelProperty我有一个大摇大摆的问题。在我的模型中,我@ApiModelProperty这样使用

private static final long serialVersionUID = -7142106197262010406L;

private int brandId;
private String brandName;
private String fullName;
private String webSite;
private String logoUrl;
private String note;

@ApiModelProperty(position = 1, required = true, value="")
public int getBrandId() {
    return brandId;
}

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

@ApiModelProperty(position = 2, required = true)
public String getBrandName() {
    return brandName;
}

public void setBrandName(String brandName) {
    this.brandName = brandName;
}

@ApiModelProperty(position = 3, required = true)
public String getFullName() {
    return fullName;
}

public void setFullName(String fullName) {
    this.fullName = fullName;
}

@ApiModelProperty(position = 4, required = true)
public String getWebSite() {
    return webSite;
}

public void setWebSite(String webSite) {
    this.webSite = webSite;
}

@ApiModelProperty(position = 5, required = true)
public String getLogoUrl() {
    return logoUrl;
}

public void setLogoUrl(String logoUrl) {
    this.logoUrl = logoUrl;
}

@ApiModelProperty(position = 6, required = true)
public String getNote() {
    return note;
}

public void setNote(String note) {
    this.note = note;
}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么@ApiModelProperty不工作。谁能帮我解决这个问题。请。感谢大家!

小智 2

您是否用 @ApiModel 注释了您的类?

@ApiModel
public class Brand{

   private String brandName;
   //...

    @ApiModelProperty(position = 1, required = true, value="")
    public int getBrandId() {
        return brandId;
    }

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

    //...
}
Run Code Online (Sandbox Code Playgroud)

  • 我的类注释为“@ApiModel”,但“position”参数仍然被忽略 - swagger-ui 中生成的 JSON 仍然按字母顺序排列其字段。 (2认同)