具体内容如下
现在的需求的:
根据产品族、产品类型,下载该产品族、产品类型下面的pic包;
pic包是zip压缩文件;
t_product表:
这些包以blob形式存在另一张表中:
t_imagefile表:
现在要做的是:将接入网、OLT下面的两个包downloadPIC:MA5800系列-pic.zip 和 MA5900-pic.rar一起打包成zip压缩文件下载下来;
代码:
ProductController.java:
/** * 根据产品族、产品类型下载照片包 */ @RequestMapping("/downloadwBatch") public void downloadwBatch(HttpServletRequest request, HttpServletResponse response, String productFamily, String productType){ //http://localhost:8080/MySSM/downloadwBatch?productFamily=接入网&productType=OLT try { productFamily = new String(productFamily.getBytes("iso-8859-1"), "utf-8"); productType = new String(productType.getBytes("iso-8859-1"), "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } //获取要下载的照片包名 Map
ProductService.java:
/** * 根据包名获取文件 */ public byte[] getPackage(String packageName){ byte[] bag = null; try{ ImageFile m = productMapper.getPackage(packageName); if(m!=null){ bag = m.getPicture(); } }catch(Exception e){ e.printStackTrace(); } return bag; } /** * 根据产品族、产品类型 获取待下载的包名 * @param params * @return */ public List
ProductMapper.java:
/** * 根据包名获取文件 */public ImageFile getPackage(String packageName) throws Exception; /** * 据产品族、产品类型 获取待下载的包名 */public List
ProductMapper.xml:
测试:
在浏览器中输入:http://localhost:8080/MySSM/downloadwBatch?productFamily=接入网&productType=OLT
简单的demo
package com.msznyl; import java.io.BufferedInputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.util.zip.ZipEntry;import java.util.zip.ZipOutputStream;public class Download { public static void main(String[] args) { //需要压缩的文件--包括文件地址和文件名 String [] path ={"E:\\360DocProtect\1.txt","E:\\360DocProtect\2.docx"}; // 要生成的压缩文件地址和文件名称 String desPath = "D:\\DOWNLOADS\\new.zip"; File zipFile = new File(desPath); ZipOutputStream zipStream = null; FileInputStream zipSource = null; BufferedInputStream bufferStream = null; try { //构造最终压缩包的输出流 zipStream = new ZipOutputStream(new FileOutputStream(zipFile)); for(int i =0;i
上一篇:java常见字符串使用方法有哪些