如何在浏览器中使用spring boot在单个页面中呈现多个文档



在我的应用程序中,Employee(Entity)可以有许多Document(Entity)。员工可以在我的网站上上传他的文件。我想给员工一个查看选项,让他们查看他的所有文件。每当用户单击"查看"按钮时,我只能在浏览器中显示一个文档。但我不知道每当用户点击查看按钮时,如何在浏览器中显示所有文档。

这是我只显示一个文档的代码

@GetMapping("/showDocument")
public ResponseEntity<byte[]> showDocument(
@RequestParam("employeeId") int employeeId
) throws IOException, SQLException {
Employee employee = employeeService.findById(employeeId);
HttpHeaders httpHeaders = new HttpHeaders();
ResponseEntity<byte[]> responseEntity = null;
if (employee != null && employee.getDocuments() != null) {
Document document = employee.getDocuments().get(0);
InputStream inputStream = document.getContent().getBinaryStream();
httpHeaders.setCacheControl(CacheControl.noCache().getHeaderValue());
httpHeaders.set(CONTENT_TYPE, document.getContentType());
byte[] media = IOUtils.toByteArray(inputStream);
responseEntity = new ResponseEntity<>(media, httpHeaders, HttpStatus.OK);
}
return responseEntity;
}

如果我必须设计这个解决方案,我不会在一次调用中获取所有文档,因为这会对网络造成沉重负担,而且速度也会较慢。事实上,我只会获取元数据以缩略图的形式显示文档,并在用户单击特定缩略图时按需获取特定文档。

最新更新