我的代码以这种方式工作,但是有什么方法可以将我在这种情况下需要的 Response 方法与 Spring boot 注释相结合而不返回整个响应数据?
我猜测带有 PostMapping 的 RestController 包含 Response 返回所有内容。
@RestController
@RequestMapping("/v1")
public class Resource {
@PostMapping(value = "/post")
public Response post(@RequestBody final Data data) {
Response response = null;
try {
validateData(data);
LOG.info("SUCCESS");
response = Response.status(Status.OK).entity("Success").build();
} catch (Exception e) {
LOG.error(e.getMessage(), e.getCause());
response = Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
}
return response;
}
{
"context": {
"headers": {},
"entity": "Success",
"entityType": "java.lang.String",
"entityAnnotations": [],
"entityStream": {
"committed": false,
"closed": false
},
"stringHeaders": {},
"mediaType": null,
"allowedMethods": [],
"committed": false, …Run Code Online (Sandbox Code Playgroud)