Why response from annotated endpoints is empty?
因为你的方法返回void(没有body的意思).状态代码 – 它不是一个正文.
您可以尝试此操作以返回具有消息明确性的响应:
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public ResponseEntity delete(@PathVariable("id") String id) {
repo.removeById(id);
return new ResponseEntity<>("Your message here", HttpStatus.OK);
}
而不是ResponseEntity< String>你可以把ResponseEntity< YourCustomObject>然后返回新的ResponseEntity<>(yourCustomObject实例,HttpStatus.OK);它将在响应期间转换为JSON.
你也可以这样做:
@ResponseStatus(value = HttpStatus.OK,reason =“某种原因”)
在这种情况下,您将返回以下内容:
{
"timestamp": 1504007793776,
"status": 200,
"error": "OK",
"message": "Some reason",
"path": "/yourPath"
}