2020-12-10
springBoot 整合log4j 2 在訪問介面文件的時候會出現下面這個錯誤
java.lang.NumberFormatException: For input string: ""
後端原始介面
@ApiOperation(value = "根據id獲取使用者")
@GetMapping("{id}")
public ApiResult getUser(@ApiParam(name = "id", value = "使用者id",required = true) @PathVariable("id") Long id) {
SysUser sysUser = sysUserService.getUser(id);
return ApiResult.ok(sysUser);
}
分析原因:
原因就是引數沒有預設值,需要一個long,但是空值預設為""
解決方式:
在介面中新增預設值example屬性值:
@ApiOperation(value = "根據id獲取使用者")
@GetMapping("{id}")
public ApiResult getUser(@ApiParam(name = "id", value = "使用者id",example = "120",required = true) @PathVariable("id") Long id) {
SysUser sysUser = sysUserService.getUser(id);
return ApiResult.ok(sysUser);
}