适用版本:1.0.0_20170726
1:构建方法参数 RData对象,其中: key: fileName 导出文件的文件名,后缀必须为zip key: fileList 一个list<RData>对象,存放需要压缩的文件列表 fileList对象中每一个item都必须为rdata对象,其需要包含 key: dirPath 表示压缩包内的文件名或者报名,必须为包内全路径名 key: file 实际文件的全路径 2:方法编写 与常规方法一样。; 3:方法底部 request.setAttribute("file", rdata);//必须将构造的参数放入request的file字段内 return "forward:"+ adminPath+"/file/downloadZip";//原样复制即可
示例代码 @RequestMapping("download") public String download(HttpServletRequest request) throws IOException { rdata.set("fileName", "test.zip");//文件名 ArrayList<RData> fileList = new ArrayList<RData>(); rdata.set("fileList", fileList);//压缩包内文件列表 RData file1 = new RData(); file1.set("dirPath", "sss1/");//构建一个空的文件夹,名称为sss1,不需要建立空白文件夹则这步不需要写 file1.set("file", "/");//如果构建文件夹,则需要传入“/” fileList.add(file1); file1 = new RData(); file1.set("dirPath", "og4j.properties");//构建一个压缩包的文件,名称为log4j.properties, file1.set("file", "D:\\T9_dntg\\T9NuoYa\\Server\\log4j.properties");//具体放入压缩包内的文件绝对地址 fileList.add(file1); file1 = new RData(); file1.set("dirPath", "sss/og4j.properties");//构建一个压缩包的文件,名称为log4j.properties,包内存放位置为:sss\log4j.properties file1.set("file", "D:\\T9_dntg\\T9NuoYa\\Server\\log4j.properties");//具体放入压缩包内的文件绝对地址 fileList.add(file1); file1 = new RData(); file1.set("dirPath", "测试\\测试.xml");//构建一个压缩包的文件,名称为测试.xml,包内存放位置为:测试\测试.xml file1.set("file", "D:\\T9_dntg\\T9NuoYa\\Server\\log4j2.xml");//具体放入压缩包内的文件绝对地址,改文件放入包内后,会改变为dirPath指定的文件名 fileList.add(file1); request.setAttribute("file", rdata); return "forward:"+ adminPath+"/file/downloadZip"; }
|