本文已参与「新人创作礼」活动,一起开启掘金创作之路。
spring boot和swagger中隐藏请求参数 低版本的swagger不支持,高版本的swagger(目前已知2.6.0 及以上版本支持)
则可使用 hidden = true 隐藏参数
import io.swagger.annotations.ApiModelProperty; @ApiModelProperty(value = "部门编码#<非空>", notes ="部门编码",required = false,hidden = true) private String bbb;
此外也可以使用 @JsonIgnore ,但是这个会导致返回的数据也排除这个字段,所以慎用
如果想允许接收不返回则可加上 @JsonProperty ,此时可接收数据,不返回数据,不过也有缺点,目前的
swagger1.9,会导致 @ApiModelProperty 里的 注释(value属性),值(example属性)不能显示
import springfox.documentation.annotations.ApiIgnore; @JsonIgnore @JsonProperty @ApiModelProperty(value = "bbb", notes ="部门编码bbb",required = false) private String bbb; 所以最好的办法就是,完美
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY) @ApiModelProperty(value = "(检索,不保存不返回)区间操作起始---年度", notes ="区间操作起始---年度", example = "1", hidden = true) private Integer ndStart;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY) @ApiModelProperty(value = "(检索,不保存不返回)区间操作截止---年度", notes ="区间操作截止---年度", example = "1", hidden = true) private Integer ndEnd;