Emd*_*won 1 spring spring-mvc spring-boot
我想通过spring mvc处理简单的POST请求。请求正文仅包含一个int值。谁能帮我写动作方法。我的代码如下:
@PostMapping(value = "/update")
@ResponseBody
public ResponseEntity updateLogLevel(@RequestBody int level) {
try {
//process request
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
return ResponseEntity.ok(Constant.STATUS_SUCCESS);
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码抛出异常:
org.springframework.http.converter.HttpMessageNotReadableException",
"message":"JSON parse error: Can not deserialize instance of int out of START_OBJECT token;
nested exception is
com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of int out of START_OBJECT token
Run Code Online (Sandbox Code Playgroud)
我的请求正文:
{
"level" : 100
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1575 次 |
| 最近记录: |