OAF数据库动态图片的实现
2011-09-14 10:05
141 查看
将图片写入数据库:
表字段类型为BLOB,在OAF中创建对应的Item,关联到相应VO属性,Item syle 设为MessageFileUpload
提交后就会自动保存到数据库中,使用PL/SQL Developer查看图片是否存储。
读取图片并在网页中显示:
流程:获取临时文件夹物理路径---从VO读取数据---使用IO流输出图片-修改Image Item的Source属性。
获取临时文件夹物理路径(CO代码):
view plaincopy to clipboardprint?
//物理路径
String phyPath = pageContext.getTemporaryImageLocation();
//相对路径
String relPath = pageContext.getTemporaryImageSource();
/*以下两行注释用于生成唯一图片名,可视需要使用*/
//String imageName = pageContext.generateUniqueImageName("UserIcon.gif",
//OAWebBeanConstants.OA_TEMPORARY_IMAGE);
String imageName = "UserIcon"+user_id+".gif";
Serializable[] parameters = { user_id, phyPath, imageName };
am.invokeMethod("queryUser", parameters);
//物理路径
String phyPath = pageContext.getTemporaryImageLocation();
//相对路径
String relPath = pageContext.getTemporaryImageSource();
/*以下两行注释用于生成唯一图片名,可视需要使用*/
//String imageName = pageContext.generateUniqueImageName("UserIcon.gif",
//OAWebBeanConstants.OA_TEMPORARY_IMAGE);
String imageName = "UserIcon"+user_id+".gif";
Serializable[] parameters = { user_id, phyPath, imageName };
am.invokeMethod("queryUser", parameters);
使用IO流输出图片(AM代码):
view plaincopy to clipboardprint?
private void initImage(BlobDomain image, String phyPath,
String imageName) {
File directory = new File(phyPath);
if (!directory.exists())
directory.mkdirs();
File imageFile = new File(directory, imageName);
try {
fromInputToOutput(image.getBinaryStream(),
new FileOutputStream(imageFile));
} catch (Exception exception) {
exception.printStackTrace();
}
//DEBUG专用,看看路径对不对
System.out.println(imageFile.getAbsolutePath());
}
/*复制方法,图片大可以增大byte块*/
public void fromInputToOutput(InputStream inputstream,
OutputStream outputstream) throws IOException {
byte abyte0[] = new byte[255];
for (int i = 255; i == 255; ) {
i = inputstream.read(abyte0);
if (i < 0)
break;
outputstream.write(abyte0, 0, i);
}
outputstream.close();
inputstream.close();
}
private void initImage(BlobDomain image, String phyPath,
String imageName) {
File directory = new File(phyPath);
if (!directory.exists())
directory.mkdirs();
File imageFile = new File(directory, imageName);
try {
fromInputToOutput(image.getBinaryStream(),
new FileOutputStream(imageFile));
} catch (Exception exception) {
exception.printStackTrace();
}
//DEBUG专用,看看路径对不对
System.out.println(imageFile.getAbsolutePath());
}
/*复制方法,图片大可以增大byte块*/
public void fromInputToOutput(InputStream inputstream,
OutputStream outputstream) throws IOException {
byte abyte0[] = new byte[255];
for (int i = 255; i == 255; ) {
i = inputstream.read(abyte0);
if (i < 0)
break;
outputstream.write(abyte0, 0, i);
}
outputstream.close();
inputstream.close();
}
注解:
1.如果不需要显示图片,而只是提供下载,那么使用MessageDownload会容易得多(无需手动输出)
2.Image Item也可以用代码创建。
3.由于OAF默认的图片文件夹是在OA_MEDIA下,如果使用视图的临时变量作为Image Item的 Image URL引用,图片地址会错误
4.将图片存储于数据库中管理不易,性能也不如直接保存图片URL的好
5.生成的图片不论原格式是JPG.PNG或是GIF,统一为GIF浏览器也可以显示出来
6.此代码没有做安全处理,包括上传文件大小和文件类型
表字段类型为BLOB,在OAF中创建对应的Item,关联到相应VO属性,Item syle 设为MessageFileUpload
提交后就会自动保存到数据库中,使用PL/SQL Developer查看图片是否存储。
读取图片并在网页中显示:
流程:获取临时文件夹物理路径---从VO读取数据---使用IO流输出图片-修改Image Item的Source属性。
获取临时文件夹物理路径(CO代码):
view plaincopy to clipboardprint?
//物理路径
String phyPath = pageContext.getTemporaryImageLocation();
//相对路径
String relPath = pageContext.getTemporaryImageSource();
/*以下两行注释用于生成唯一图片名,可视需要使用*/
//String imageName = pageContext.generateUniqueImageName("UserIcon.gif",
//OAWebBeanConstants.OA_TEMPORARY_IMAGE);
String imageName = "UserIcon"+user_id+".gif";
Serializable[] parameters = { user_id, phyPath, imageName };
am.invokeMethod("queryUser", parameters);
//物理路径
String phyPath = pageContext.getTemporaryImageLocation();
//相对路径
String relPath = pageContext.getTemporaryImageSource();
/*以下两行注释用于生成唯一图片名,可视需要使用*/
//String imageName = pageContext.generateUniqueImageName("UserIcon.gif",
//OAWebBeanConstants.OA_TEMPORARY_IMAGE);
String imageName = "UserIcon"+user_id+".gif";
Serializable[] parameters = { user_id, phyPath, imageName };
am.invokeMethod("queryUser", parameters);
view plaincopy to clipboardprint? public void queryUser(String user_id, String phyPath, String imageName) { //此处调用了视图的查询方法 getUserVO1().initQuery(new Number(Integer.parseInt(user_id))); OAViewObject vo = (OAViewObject)getUserVO1(); BlobDomain image = null; if (vo.hasNext()) { Row row = vo.next(); image = (BlobDomain)row.getAttribute("Icon"); if (image != null) initImage(image, phyPath, imageName); } } public void queryUser(String user_id, String phyPath, String imageName) { //此处调用了视图的查询方法 getUserVO1().initQuery(new Number(Integer.parseInt(user_id))); OAViewObject vo = (OAViewObject)getUserVO1(); BlobDomain image = null; if (vo.hasNext()) { Row row = vo.next(); image = (BlobDomain)row.getAttribute("Icon"); if (image != null) initImage(image, phyPath, imageName); } } public void queryUser(String user_id, String phyPath, String imageName) { //此处调用了视图的查询方法 getUserVO1().initQuery(new Number(Integer.parseInt(user_id))); OAViewObject vo = (OAViewObject)getUserVO1(); BlobDomain image = null; if (vo.hasNext()) { Row row = vo.next(); image = (BlobDomain)row.getAttribute("Icon"); if (image != null) initImage(image, phyPath, imageName); } } public void queryUser(String user_id, String phyPath, String imageName) { //此处调用了视图的查询方法 getUserVO1().initQuery(new Number(Integer.parseInt(user_id))); OAViewObject vo = (OAViewObject)getUserVO1(); BlobDomain image = null; if (vo.hasNext()) { Row row = vo.next(); image = (BlobDomain)row.getAttribute("Icon"); if (image != null) initImage(image, phyPath, imageName); } }
使用IO流输出图片(AM代码):
view plaincopy to clipboardprint?
private void initImage(BlobDomain image, String phyPath,
String imageName) {
File directory = new File(phyPath);
if (!directory.exists())
directory.mkdirs();
File imageFile = new File(directory, imageName);
try {
fromInputToOutput(image.getBinaryStream(),
new FileOutputStream(imageFile));
} catch (Exception exception) {
exception.printStackTrace();
}
//DEBUG专用,看看路径对不对
System.out.println(imageFile.getAbsolutePath());
}
/*复制方法,图片大可以增大byte块*/
public void fromInputToOutput(InputStream inputstream,
OutputStream outputstream) throws IOException {
byte abyte0[] = new byte[255];
for (int i = 255; i == 255; ) {
i = inputstream.read(abyte0);
if (i < 0)
break;
outputstream.write(abyte0, 0, i);
}
outputstream.close();
inputstream.close();
}
private void initImage(BlobDomain image, String phyPath,
String imageName) {
File directory = new File(phyPath);
if (!directory.exists())
directory.mkdirs();
File imageFile = new File(directory, imageName);
try {
fromInputToOutput(image.getBinaryStream(),
new FileOutputStream(imageFile));
} catch (Exception exception) {
exception.printStackTrace();
}
//DEBUG专用,看看路径对不对
System.out.println(imageFile.getAbsolutePath());
}
/*复制方法,图片大可以增大byte块*/
public void fromInputToOutput(InputStream inputstream,
OutputStream outputstream) throws IOException {
byte abyte0[] = new byte[255];
for (int i = 255; i == 255; ) {
i = inputstream.read(abyte0);
if (i < 0)
break;
outputstream.write(abyte0, 0, i);
}
outputstream.close();
inputstream.close();
}
view plaincopy to clipboardprint? OAImageBean image = (OAImageBean)webBean.findIndexedChildRecursive("Icon"); if (image != null) { image.setSource(relPath + imageName);} OAImageBean image = (OAImageBean)webBean.findIndexedChildRecursive("Icon"); if (image != null) { image.setSource(relPath + imageName);} OAImageBean image = (OAImageBean)webBean.findIndexedChildRecursive("Icon"); if (image != null) { image.setSource(relPath + imageName);} OAImageBean image = (OAImageBean)webBean.findIndexedChildRecursive("Icon"); if (image != null) { image.setSource(relPath + imageName);}
注解:
1.如果不需要显示图片,而只是提供下载,那么使用MessageDownload会容易得多(无需手动输出)
2.Image Item也可以用代码创建。
3.由于OAF默认的图片文件夹是在OA_MEDIA下,如果使用视图的临时变量作为Image Item的 Image URL引用,图片地址会错误
4.将图片存储于数据库中管理不易,性能也不如直接保存图片URL的好
5.生成的图片不论原格式是JPG.PNG或是GIF,统一为GIF浏览器也可以显示出来
6.此代码没有做安全处理,包括上传文件大小和文件类型
相关文章推荐
- OAF数据库动态图片的实现
- OAF数据库动态图片的实现
- SpringBoot整合mybatis、shiro、redis实现基于数据库的细粒度动态权限管理系统实例
- Express实现前端后端通信上传图片之存储数据库(mysql)傻瓜式教程(一)
- Hibernate实现将图片保存至数据库、显示在页面
- 【代码】PHP 生成GIF动画实现动态图片验证码
- 非常平滑的JS图片滚动特效代码,无缝循环,速度可自定义,鼠标悬停时停止。它的特点是JS和图片地址分离,这样做你就经易的从数据库动态调用每张图片的地址,方便控制,因此它非常的应用。
- vc实现图片的数据库储存(转载)
- 如何实现图片的动态切换(间隔几秒就切换下一张)
- 用Seam实现:图片上传 + 保存到数据库 + 从数据库读出图片并显示到页面中
- Glide 实现圆形图片 并动态旋转
- ViewPager实现加载网络图片,动态添加删除效果
- 用Seam实现:图片上传 + 保存到数据库 + 从数据库读出图片并显示到页面中
- 用java实现动态菜单的显示--数据库实现与菜单参数初始化
- 鼠标放到图片上实现动态的效果
- OAF中实现动态LOV
- ScrollView实现图片拉伸效果,仿QQ好友动态头部效果
- java spring+mybatis整合实现爬虫之《今日头条》搞笑动态图片爬取
- JavaScript之动态改变img标签里面的src属性实现图片的循环切换
- php从数据库中取二进制流文件转换为图片,图片以二进制流存入数据库实现