场景描述
使用@RequestBody来接受参数,但是http请求中的request中Body为空,导致异常。
异常信息
[http-nio-8080-exec-7] ERROR o.jeecg.common.exception.JeecgBootExceptionHandler:79 - Required request body is missing: xxx
org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing:xxx
解决方法
在@RequestBody后加上 (required = false)
@PostMapping(value = "/ConfigurableStart")
public Result<String> ConfigurableStart(@RequestBody(required = false) JSONObject jsonObject){
return null;
}
加了 (required = false) 之后,若http请求中的request中Body为空,则参数为null,不会报错。