I am having trouble passing multiple parameters to GET resource in my controller. I have created a named query in my repository. When i call this GET endpoint, it should execute the named query by passing parameters.
Below code should take multiple parameters as input for example ID = 1,2,3,4 etc. It only takes single input as param.
@GetMapping("/message/{Ids}")
@CrossOrigin(origins = "*")
public void multidownload(@PathVariable Long[] Ids , HttpServletResponse response)throws Exception {
List<MessageRepository> messageRepository = Repository.findbyId(Ids);
String xml = new ObjectMapper().writeValueAsString(messageRepository);
String fileName = "message.zip";
String xml_name = "message.xml";
byte[] data = xml.getBytes();
byte[] bytes;
try (ByteOutputStream bout = new ByteOutputStream();
ZipOutputStream zout = new ZipOutputStream(bout)) {
zout.setLevel(1);
ZipEntry ze = new ZipEntry(xml_name);
ze.setSize(data.length);
zout.putNextEntry(ze);
zout.write(data);
zout.closeEntry();
bytes = bout.getBytes();
}
response.setContentType("application/zip");
response.setContentLength(bytes.length);
response.setHeader("Content-Disposition", "attachment; " + String.format("filename=" + fileName));
ServletOutputStream outputStream = response.getOutputStream();
FileCopyUtils.copy(bytes, outputStream);
outputStream.close();
}
downloaded zip file should contain multiple ID records which were passed as parameter when calling the GET endpoint.
can someone look into my code and point out what needs changing?