1、controller层
/**
* 压缩打包文件下载到浏览器默认路径
* @return
*/
@RequestMapping(value="/downloadZipFile")
@ResponseBody
public Object compressedFile(@RequestParam(value = "docIds",required = false)String docIds){
List<File> files=new ArrayList<>();
List<String> list=new ArrayList<>();
String[] idList =docIds.split(",");
for (String id:idList){
list.add(id);
}
List<DocManager> atttendanchList = docManagerService.selByAttendanceId(list);
for (DocManager docManager:atttendanchList){
File file = new File(docManager.getDocPath()+docManager.getFileName());
files.add(file);
}
//将多个文件压缩打包,下载到默认浏览器
try {
File zipFile=FileUtil.fileToZip(files,zipFilePath,ContentUtil.randomGen(6));//将多文件打包为zip文件
FileSystemResource fileSource = new FileSystemResource(zipFile);