标签:servlet 从服务器 orm 服务器 output ice catch else img
图片的数据数据库中存储:
else if ("/cake/getImg.do".equals(req.getServletPath())) { String idStr = req.getParameter("id"); Cake cake = cakeService.getCakeImg(Long.valueOf(idStr)); //通过Mybatis获取图片的数据,封装在cake这个类中 try { resp.setContentType("multipart/form-data"); if (null != cake && null != cake.getSmallImg()) { InputStream in = new ByteArrayInputStream(cake.getSmallImg()); ServletOutputStream out = resp.getOutputStream(); byte[] b = new byte[1024]; int length = in.read(b); while (length != -1) { out.write(b); length = in.read(b); } out.flush(); out.close(); in.close();resp.flushBuffer(); } } catch (IOException e) { e.printStackTrace(); } } }
标签:servlet 从服务器 orm 服务器 output ice catch else img
原文地址:https://www.cnblogs.com/shouyaya/p/12495605.html