我们的控制器看起来像这样 -
@RestController
@RequestMapping(value="api")
@Validated
public class SampleController {
@RequestMapping(value = {"/test"}, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public void test(
@RequestParam(value = "testCode",required=true) String merchantCode
) throws Exception{
System.out.print("This is Test");
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,如果我们没有在请求中指定所需的参数“testCode”,我们会得到“400 Bad Request”,但错误响应的消息部分仍为空白。
我们得到的回应 -
{"timestamp":1592441286607,"status":400,"error":"Bad Request","message":"","path":"/test"}
Run Code Online (Sandbox Code Playgroud)
但预计的是——
{"timestamp":1592441286607,"status":400,"error":"Bad Request","message":"Required String parameter 'testCode' is not present","path":"/test"}
Run Code Online (Sandbox Code Playgroud)
我们正在使用以下 Spring 依赖项 -
<spring-boot.version>2.3.0.RELEASE</spring-boot.version>
<spring-framework.version>5.2.6.RELEASE</spring-framework.version>
Run Code Online (Sandbox Code Playgroud)
我所看到的是,我们得到了 MissingServletRequestParameterException,但在异常中消息为空白(“”)。