felx和springHibernate整合传递二进制数据到表中并在flex的dataGrid控件中显示的实践.doc_第1页
felx和springHibernate整合传递二进制数据到表中并在flex的dataGrid控件中显示的实践.doc_第2页
felx和springHibernate整合传递二进制数据到表中并在flex的dataGrid控件中显示的实践.doc_第3页
felx和springHibernate整合传递二进制数据到表中并在flex的dataGrid控件中显示的实践.doc_第4页
felx和springHibernate整合传递二进制数据到表中并在flex的dataGrid控件中显示的实践.doc_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

一、 创建数据库表(使用ms sql2005)create database mydbgouse mydbgocreate table pic(pid int identity primary key, pname varchar(50), photo image)select * from pic二、 建立web工程,并加入相应的spring2.5x的组件包和Hibernate3.x组件包,通过MyEclipse8.x工具生成相应的实体类、映射文件和dao类,生成以后,需要将photo属性类型更改为byte类型,并修改相应的映射文件的类型private byte photo;public byte getPhoto() return this.photo;public void setPhoto(byte photo) this.photo = photo;映射文件的类型改为以下类型 注意:一定要修改,这个很重要完成以上操作以后,将Blazds.war文件解压缩,将其WEB-INF目录下的flex目录和lib目录拷贝到当前工程的WEB-INF目录下。三、 编写业务类,并实现其CRUD方法(1)、业务接口package com.business;import java.util.List;public interface IBusiness public boolean save(Object ob);public boolean update(Object ob);public boolean delById(String id);public Object findById(String id);public List findAll();(2)业务实现package com.business;import java.util.*;import com.dao.PicDAO;import com.po.*;public class PicBusiness implements IBusiness private PicDAO pdao;public PicDAO getPdao() return pdao;public void setPdao(PicDAO pdao) this.pdao = pdao;public boolean delById(String id) / TODO Auto-generated method stubreturn false;public List findAll() / TODO Auto-generated method stubreturn pdao.findAll();public Object findById(String id) / TODO Auto-generated method stubreturn null;public boolean save(Object ob) / TODO Auto-generated method stubPic pic=(Pic) ob;try pdao.save(pic);return true; catch (Exception e) / TODO Auto-generated catch blocke.printStackTrace();return false;public boolean update(Object ob) / TODO Auto-generated method stubreturn false;因为只用到增加和显示,所以其他方法未实现四、 在applicationContext.xml文件中的配置方式org.hibernate.dialect.SQLServerDialecttruecom/po/Pic.hbm.xml修改WEB-INF/web.xml文件,如下所示: contextConfigLocation /WEB-INF/applicationContext.xml flex.messaging.HttpFlexSession org.springframework.web.context.ContextLoaderListener MessageBrokerServlet flex.messaging.MessageBrokerServlet services.configuration.file /WEB-INF/flex/services-config.xml 1 MessageBrokerServlet /messagebroker/* index.jsp BASIC 五、 整合flex需要的SpringFactory类(官方提供的,代码如下),把这个类放置在src的根目录下public class SpringFactory implements FlexFactory private static final String SOURCE = source; /* * This method can be used to initialize the factory itself. It is called with configuration * parameters from the factory tag which defines the id of the factory. */ public void initialize(String id, ConfigMap configMap) /* * This method is called when we initialize the definition of an instance * which will be looked up by this factory. It should validate that * the properties supplied are valid to define an instance. * Any valid properties used for this configuration must be accessed to * avoid warnings about unused configuration elements. If your factory * is only used for application scoped components, this method can simply * return a factory instance which delegates the creation of the component * to the FactoryInstances lookup method. */ public FactoryInstance createFactoryInstance(String id, ConfigMap properties) SpringFactoryInstance instance = new SpringFactoryInstance(this, id, properties); instance.setSource(properties.getPropertyAsString(SOURCE, instance.getId(); return instance; / end method createFactoryInstance() /* * Returns the instance specified by the source * and properties arguments. For the factory, this may mean * constructing a new instance, optionally registering it in some other * name space such as the session or JNDI, and then returning it * or it may mean creating a new instance and returning it. * This method is called for each request to operate on the * given item by the system so it should be relatively efficient. * * If your factory does not support the scope property, it * report an error if scope is supplied in the properties * for this instance. */ public Object lookup(FactoryInstance inst) SpringFactoryInstance factoryInstance = (SpringFactoryInstance) inst; return factoryInstance.lookup(); static class SpringFactoryInstance extends FactoryInstance SpringFactoryInstance(SpringFactory factory, String id, ConfigMap properties) super(factory, id, properties); public String toString() return SpringFactory instance for id= + getId() + source= + getSource() + scope= + getScope(); public Object lookup() ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(flex.messaging.FlexContext.getServletConfig().getServletContext(); String beanName = getSource(); try return appContext.getBean(beanName); catch (NoSuchBeanDefinitionException nexc) ServiceException e = new ServiceException(); String msg = Spring service named + beanName + does not exist.; e.setMessage(msg); e.setRootCause(nexc); e.setDetails(msg); e.setCode(Server.Processing); throw e; catch (BeansException bexc) ServiceException e = new ServiceException(); String msg = Unable to create Spring service named + beanName + ; e.setMessage(msg); e.setRootCause(bexc); e.setDetails(msg); e.setCode(Server.Processing); throw e; 六、 在当前工程的WEB-INF/flex目录下修改services-config.xml文件,加入以下配置信息:七、 修改WEB-INF/flex目录下修改remoting-config.xml文件,加入以下配置信息:springpicBusiness其中,picBusiness表示为applicationContext.xml文件中配置的业务类的id标示八、 将web工程转为flex工程九、 编写与实体类对应的flex中的as类文件,文件如下所示package com.beanimport flash.utils.ByteArray;RemoteClass(alias=com.po.Pic)public class Picpublic function Pic()public var pid:int;public var pname:String;public var photo:ByteArray;其中photo属性为ByteArray类型与com.po.Pic类中的photo属性的byte类型匹配十、 建立flex的应用,如图所示新建的文件名为picadd.mxml文件,并打开设计视图,页面布局如下Picadd.mxml文件的代码

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论