0
spring mvcによる簡単なPOSTリクエストを処理したい。要求本体には、単一のint値のみが含まれます。誰でも私にアクションメソッドを書くのを助けることができますか?私のコードは以下の通りです:Spring MVC Mapリクエスト本体からプリミティブ型へ
@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);
}
しかし、このコードのスロー例外:
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
マイリクエストボディ:
{
"level" : 100
}
あなたはあなたのrの本文を共有できますか?平等? –
@AmerQarabsaリクエストボディを共有しました –