2

我有@RestController如下端点(spring-boot 版本 1.5.9.RELEASE)

@RestController
public class Controller
{
    @PostMapping(value = "profile", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Profile profile(@RequestBody Request request) {
        ... ... ...
        return profileObj;
    }
}

每当我调用上面的端点时,我都会收到带有以下标题的响应,

.... ... ...
Access-Control-Allow-Headers:
Cache-Control: no cache, no-store, must-revalidate
Content-Type: application/json;charset=utf-8
Transfer-Encoding: chunked

我想禁用传输编码,即我需要包含内容长度。

我有很多这样的控制器。所以我不想计算每个端点的长度并返回ResponseEntity长度值。我正在寻找将自动包含内容长度的通用解决方案。有没有办法做到这一点?

4

0 回答 0