简体   繁体   English

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

[英]How to render multiple documents in single page in browser using spring boot

In my application Employee(Entity) can have many Document(Entity) .在我的应用程序中Employee(Entity)可以有很多Document(Entity) An employee can upload his documents on my website.员工可以在我的网站上上传他的文件。 I want to give a view option to the employees to see all his documents.我想为员工提供查看选项以查看他的所有文件。 I can show only one document in the browser whenever the user clicks on the view button.每当用户单击查看按钮时,我只能在浏览器中显示一个文档。 But I don't know how to show all documents all together in the browser whenever a user clicks on the view button.但是我不知道每当用户单击查看按钮时如何在浏览器中一起显示所有文档。

Here is my code for showing only one document.这是我只显示一个文档的代码。

@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;
    }

if I had to design this solution, I would not fetch all the documents in one call as this would be heavy on network and would be slower as well.如果我必须设计这个解决方案,我不会在一次调用中获取所有文档,因为这会对网络造成负担,而且速度也会变慢。 Infact I would just fetch the metadata to show documents in form of thumbnails and on demand fetch the specific document when a user click on specific thumbnail.事实上,我只会获取元数据以缩略图形式显示文档,并在用户单击特定缩略图时按需获取特定文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM