GWT - 来自数据库的图像 [英] GWT - image from database
问题描述
我实际上正在开发基于 GWT 的网站.现在我被困在如何在我的网站上显示存储在数据库中的图像.
I'm actually working on a GWT based website. Now I'm stuck on how I should display images stored in a database on my website.
基本上我的数据库中有一个字节数组,我使用休眠来获取它.现在我应该从这些数据中创建一个 ... 标签,但我不知道如何
Basically I've a bytearray in my database, which I fetch using hibernate. Now should I probably create an ... tag out of that data, but I don't know how
我在 Java 和 Hibernate 中使用 GWT
I'm using GWT in Java and Hibernate
推荐答案
这里是解决方案.首先,您应该使用 com.google.gwt.user.server.Base64Utils.toBase64(byte[]) 对字节数组进行编码.但是这个方法对IE 7 不起作用.IE8 有32kb 的限制.IE9 没有这个限制.
Here is the solution. First you should encode the byte array by using com.google.gwt.user.server.Base64Utils.toBase64(byte[]) . But this method does not work for IE 7. and IE8 has 32kb limit.. IE9 does not have this limit.
这里是服务器端的方法
public String getImageData(){
String base64 = Base64Utils.toBase64(imageByteArray);
base64 = "data:image/png;base64,"+base64;
return base64;
}
这里是客户端方法;
@Override
public void onSuccess(String imageData) {
Image image = new Image(imageData);
RootPanel.get("image").add(image);
}
这篇关于GWT - 来自数据库的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!