我无法将多个参数传递到控制器中的GET资源。我在存储库中创建了一个命名查询。当我调用此GET端点时,它应该通过传递参数来执行命名查询。
下面的代码应将多个参数作为输入,例如ID = 1,2,3,4等。它仅将单个输入作为参数。
@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();
}
下载的zip文件应包含多个ID记录,这些记录在调用GET端点时作为参数传递。
有人可以查看我的代码并指出需要更改的内容吗?