[英]How to find the content-length of Page <Entity> to be passed as the http header?
I am using spring boot along with Netflix Eureka.我正在使用 spring 引导和 Netflix Eureka。 I need to find the total length of Page to set the content-length in the HTTP response header.
我需要找到 Page 的总长度来设置 HTTP 响应 header 中的内容长度。 My controller is like this...
我的controller是这样的……
Page<exampleEntity> examplePage = null;
examplePage=exampleService.getFuntion(request, params);
HttpHeaders headers = new HttpHeaders();
headers.setContentLength(???);
return new ResponseEntity<>(Page, HttpHeaders ,HttpStatus.OK);
... ...
could anyone please help?有人可以帮忙吗?
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = null;
try {
out = new ObjectOutputStream(bos);
out.writeObject(yourObject);
out.flush();
byte[] yourBytes = bos.toByteArray();
} finally {
try {
bos.close();
} catch (IOException ex) {
// ignore close exception
}
}
Then yourBytes.length is what you need那么 yourBytes.length 就是你需要的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.