From 94c702917a238e2e020c03b8a1eb63d641dfbc90 Mon Sep 17 00:00:00 2001 From: e Date: Thu, 18 Oct 2018 23:46:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E6=88=90=E4=BA=8C=E7=BB=B4=E7=A0=81?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wm/controller/WmOmNoticeHController.java | 73 ++++++++++++++++++- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/zzjee/wm/controller/WmOmNoticeHController.java b/src/main/java/com/zzjee/wm/controller/WmOmNoticeHController.java index 391088be..f97e0862 100644 --- a/src/main/java/com/zzjee/wm/controller/WmOmNoticeHController.java +++ b/src/main/java/com/zzjee/wm/controller/WmOmNoticeHController.java @@ -5,6 +5,8 @@ import com.zzjee.wm.entity.*; import com.zzjee.wm.page.*; import com.zzjee.wm.service.WmOmNoticeHServiceI; +import java.io.*; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -69,9 +71,6 @@ import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import java.awt.image.BufferedImage; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; import java.util.Map; import org.springframework.http.ResponseEntity; @@ -2006,6 +2005,74 @@ public class WmOmNoticeHController extends BaseController { req.setAttribute("controller_name", "wmOmNoticeHController"); return new ModelAndView("common/upload/pub_excel_upload2"); } + + + /** + * 获取图片流/获取文件用于下载 + * @param response + * @param request + * @throws Exception + * http://localhost:8080/zzjee/wmOmNoticeHController/showOrDownqrcodeByurl.do?&qrvalue=1111223333 调用 + */ + @RequestMapping(value="showOrDownqrcodeByurl",method = RequestMethod.GET) + public void getQrImgByurl(HttpServletResponse response, HttpServletRequest request) throws Exception{ + request.setCharacterEncoding("UTF-8"); + String flag=request.getParameter("down");//是否下载否则展示图片 + + String qrvalue = request.getParameter("qrvalue"); + String dbpath = qrvalue+".jpg"; + String localPath=ResourceUtil.getConfigByName("webUploadpath"); + + try{ + String imgurl = localPath+File.separator+dbpath; + QRcodeUtil.encode(qrvalue,imgurl); + }catch (Exception e){ + + } + if("1".equals(flag)){ + response.setContentType("application/x-msdownload;charset=utf-8"); + String fileName=dbpath.substring(dbpath.lastIndexOf(File.separator)+1); + + String userAgent = request.getHeader("user-agent").toLowerCase(); + if (userAgent.contains("msie") || userAgent.contains("like gecko") ) { + fileName = URLEncoder.encode(fileName, "UTF-8"); + }else { + fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1"); + } + response.setHeader("Content-disposition", "attachment; filename="+ fileName); + + }else{ + response.setContentType("image/jpeg;charset=utf-8"); + } + + InputStream inputStream = null; + OutputStream outputStream=null; + try { + String imgurl = localPath+File.separator+dbpath; + inputStream = new BufferedInputStream(new FileInputStream(imgurl)); + outputStream = response.getOutputStream(); + byte[] buf = new byte[1024]; + int len; + while ((len = inputStream.read(buf)) > 0) { + outputStream.write(buf, 0, len); + } + response.flushBuffer(); + } catch (Exception e) { + + }finally{ + if(inputStream!=null){ + inputStream.close(); + } + if(outputStream!=null){ + outputStream.close(); + } + } + } + + + + + @RequestMapping(method = RequestMethod.GET) @ResponseBody public List list() {