标签:tty gif dep jpg 获取 图片显示 image abc 流转
1.页面写法
$("#zdytp").attr("src",ApiUrl+"/abc/getpic?orgid=8020");
2.后台写法(引入提示jar包即可)
IOUtils 引入依赖
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
@RequestMapping(value = "/imageDisplay")
public void imageDisplay(String orgid, HttpServletResponse response, HttpServletRequest request) throws IOException, SQLException {
HashMap<String,Object> map = service.getById(orgid);//从数据库查询这条记录信息
if (map != null && map.size() > 0) {
byte[] bytes = (byte[]) map.get("orglogo");//orglogo为blob大字段 存储kb数据
response.setContentType("image/jpeg, image/jpg, image/png, image/gif"); //设置输出流内容格式为图片格式
InputStream in1 = new ByteArrayInputStream(bytes); //将字节流转换为输入流
IOUtils.copy(in1, response.getOutputStream());//将字节从 InputStream复制到OutputStream中
}
String logoRealPathDir = request.getSession().getServletContext()
.getRealPath("/assets/images/icons.png");//获取默认图片路径
response.setContentType("image/jpeg, image/jpg, image/png, image/gif");
InputStream is = new FileInputStream(logoRealPathDir);
IOUtils.copy(is, response.getOutputStream());
}
标签:tty gif dep jpg 获取 图片显示 image abc 流转
原文地址:https://www.cnblogs.com/atsong/p/13328460.html