In my application Employee(Entity) can have many 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;
}