JAVA读取MongoDB中的二进制图片并显示在页面上
来源:互联网 发布:淘宝卖家信用等级2笔 编辑:程序博客网 时间:2024/05/20 22:27
1:Jsp页面:
<td><img src="${ctx}/mongoImg/show"></td>
2:xml配置:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xmlns:mongo="http://www.springframework.org/schema/data/mongo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"><mongo:mongo host="${resource.db.host}" port="${resource.db.port}" /><mongo:db-factory id="mongoDbFactory" dbname="gate" mongo-ref="mongo" /><bean class="org.springframework.data.mongodb.gridfs.GridFsTemplate"><constructor-arg ref="mongoDbFactory" /><constructor-arg ref="converter" /></bean><mongo:mapping-converter id="converter"/></beans>
3:java后台代码
package com.crscic.igms.manager.web;import java.io.OutputStream;import java.util.List;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.mongodb.gridfs.GridFsTemplate;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import com.mongodb.gridfs.GridFSDBFile;@Controller@RequestMapping(value = "/mongoImg")public class MongoImgController {@AutowiredGridFsTemplate gridFsTemplate;@RequestMapping(value = "/show")public void show(HttpServletRequest req, HttpServletResponse resp){try {OutputStream out = resp.getOutputStream();resp.setContentType("image/png");List<GridFSDBFile> find = gridFsTemplate.find(null);GridFSDBFile gridFSDBFile = find.get(0);gridFSDBFile.writeTo(out);out.flush();out.close();} catch (Exception e) {e.printStackTrace();}}}在JAVA代码中,因为只是个例子而已,所以我使用的是gridFsTemplate.find(null);查询的全部图片,而且数据库中只有2条数据,我这里就把第一条数据查出来作为例子了。各位可以根据自己的业务需要,在页面传递参数进来,并且查询特定的数据。
0 0
- JAVA读取MongoDB中的二进制图片并显示在页面上
- ASP.NET读取网络图片并在页面上显示
- ASP.NET读取网络图片并在页面上显示
- ASP.NET 用读取二进制代码的方法在页面上显示指定图片。
- html上面通过websocket接收二进制图片数据并显示在页面上
- 浅谈如何调用JSP读取数据库中图片并显示在页面上
- C# 读取excel里的图片并显示在页面上
- JSP读取Oracle数据库里的图片Blob字段并显示在页面上
- java以Blob形式存储,读取图片并在jsp页面显示图片流
- java 通过流的方式读取本地图片并显示在jsp 页面上(类型以jpg、png等结尾的图片)
- 图片以二进制形式存到数据库中,并从数据库中读出显示在页面上
- JAVA流在页面上显示图片
- Java通过IO流读取图片并显示在JSP页面上面
- JAVA读取数据库存放的二进制文件,并显示在JSP页面上
- java读取mysql中保存的图片并显示在jsp上
- 把mysql读取的图片显示在jsp 页面上
- 读取本地图片显示在JSP页面上
- spring boot实现上传图片并在页面上显示
- CCF | 201312-2 ISBN号码
- HDU 4135 Co-prime (容斥原理/分解质因数)
- 使用Cocoapods安装Alamofire
- oracle数据库事务并发操作
- C++默认编写并调用了那些函数(构造,析构,赋值)!!!
- JAVA读取MongoDB中的二进制图片并显示在页面上
- jquery 选择器(1) 基本丶层叠丶层次选择器
- ACM模板——区间问题(线段树 RMQ-ST)模板
- JS获取屏幕大小
- Intent详解
- java将获取到的手机端json串数据转换为java对象
- Java数组操作的10大方法
- 荷开娉婷,等一场相逢
- 小火山 zzuli 1912(密码)