访问swagger页面控制台抛异常问题解决

        当我们访问swagger页面的时候,有时候会报类型转换的异常,但是不影响项目正常运行,有强迫症的人肯定觉得很难受!出现这种问题,是由于你的参数列表中包含数字类型的参数(Long、Integer、long、int),我们只需要给这些参数的swagger说明加上默认值即可,即给example属性设置默认值,例如:

        1、参数直接在controller层的方法里面

    @ApiOperation("根据id查询")
    @ApiImplicitParam(name = "id", value = "用户id", required = true, example = "1")
    @GetMapping("/select-by-id")
    public Result<UserVO> selectById(@NotNull(message = "用户id不能为空") Long id){
        return success(userService.selectById(id));
    }
    @ApiOperation("根据id查询")
    @getMapping("/select-by-id")
    public Result<UserVO> selectById(@NotNull(message = "id不能为空") @ApiParam(value = "用户id", example = "1") Long id) {
        return success(userService.selectById(id));
    }
    @ApiOperation("用户启用/禁用接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", required = true, example = "1"),
            @ApiImplicitParam(name = "enable", value = "启用状态", required = true)})
    @PostMapping("/enable")
    public Result enable(@NotNull(message = "id不能为空") Long id, @NotNull(message = "启用状态不能为空") EnableEnum enable) {
        userService.updateEnable(id, enable);
        return success();
    }

         2、参数封装在实体里,controller层通过实体接收

@Data
@ApiModel
public class CreatUserDto implements Serializable {
    private static final long serialVersionUID = 3299083728881790797L;

    @ApiModelProperty(value = "角色Id", example = "1")
    @NotNull(message = "标签组的Id不能为空")
    private Long roleId;

    @ApiModelProperty(value = "用户名", required = true)
    @NotBlank(message = "用户名不能为空")
    private String username;

    @ApiModelProperty(value = "密码", required = true)
    @NotBlank(message = "密码不能为空")
    private String password;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值