小编Par*_*ris的帖子

javax.ws.rs.core 响应结合 Spring Boot 注释返回 json 响应中的所有内容?

我的代码以这种方式工作,但是有什么方法可以将我在这种情况下需要的 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)

java rest spring jersey spring-boot

1
推荐指数
1
解决办法
5150
查看次数

标签 统计

java ×1

jersey ×1

rest ×1

spring ×1

spring-boot ×1