我想在 REST 控制器类(方法)上添加 JSON 消息。例如我有删除方法看起来像:
@DeleteMapping("/people/{id}")
public ResponseEntity<PersonDto> deletePerson(@PathVariable Long id) {
return personService
.deletePerson(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
我想返回已删除的消息人(可能是 id 数)。我应该使用 ExceptionHandler 吗?或者我可以使用 exceptionHnadler 来做到这一点吗?