图片导出

从数据库里获取图片对象,然后用流输出
Object[] obj = {fpdm,fphm};
		String sql = "select t.image as img from Bus_income_Image t where t.fpdm = ? and t.fphm = ? ";
		Map image = DataTool.executeQueryOne(sql, obj);
		
		if (image == null || image.size() != 1) {
			throw new RuntimeException("没有找到指定的图片");
		}
		BLOB blob = (BLOB)image.get("img");
		try {
			String fileName = CommonUtil.getUuid();
			resp.reset();
			resp.setContentType("image/bmp");
			resp.setHeader("Content-disposition","attachment; filename=" + fileName+".tif"); 
			OutputStream  out = resp.getOutputStream();
		    InputStream in = blob.getBinaryStream();
		    int i;
		    while ((i = in.read()) != -1){
		    	out.write(i);
		    }
		    // 关闭输入、输出流
		    in.close();
		    out.close();
		} catch(Exception e){
		}finally {
			
		}

你可能感兴趣的:(导出)