swagger2的io.swagger.models.parameters.AbstractSerializableParameter异常解决步骤

1.进入http://127.0.0.1:9528/swagger-ui.html页面或刷新,控制台报如下错误:

swagger2的io.swagger.models.parameters.AbstractSerializableParameter异常解决步骤_第1张图片

2.这是由于实体类使用@ApiModelProperty时,example属性没有赋值导致的,在AbstractSerializableParameter的getExample方法中会将数值属性的example的转换数值类返回,example的默认值是"",因此当example没有赋值时,会出现上面的异常

3.只要将每一个数值类型上@ApiModelProperty的example都赋值数字字符串即可

@Data
@Excel("导入学校信息")
@TableName("biz_school")
@ApiModel(description = "学校实体")
@EqualsAndHashCode(callSuper = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BizSchool implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    @ApiModelProperty(value = "主键ID", example = "123")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 学校名称
     */
    @ApiModelProperty(value = "学校名称")
    @ExcelField(value = "学校名称", required = true)
    private String schoolName;

}

4.如果依旧未能解决,请在controller层@ApiImplicitParam加上example赋值字符串数值

@ApiOperation(value = "学校信息分页查询API", httpMethod = "POST")
@ApiImplicitParams({
        @ApiImplicitParam(dataType = "string", name = "schoolName", value = "学校名称"),
        @ApiImplicitParam(dataType = "int", name = "schoolAreaId", value = "学校地址",example = "1"),
        @ApiImplicitParam(dataType = "string", name = "schoolDoctor", value = "学校校医")
}

5.然后就可以愉快的玩耍了

你可能感兴趣的:(boot)