精华帖 (0) :: 良好帖 (0) :: 新手帖 (2) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-10-20
最后修改:2009-01-16
1下载支持文件flex-spring.zip 新建FlexLCDS工程File -> new -> Flex Project 这里不细说这个。请看http://nic.iteye.com/blog/247604 前端是flex.中间层使用spring接着hibernate,spring+hibernate的集成方法和j2ee的项目中方法相同
修改WEB-INF\web.xml ,加入下面代码
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
注册sping factory, 修改WEB-INF\flex配置
<factory id="springFactory" class="cn.org.coral.core.flex.factory.FlexSpringFactory" />
Class属性填写第一步中考入项目SpringFactory类的路径 3 注册bean到remoting-config.xml <destination id="teacherDao"> <properties> <factory>springFactory</factory> <source>TeacherDAO</source> </properties> </destination>
编写SpringFactory.java
public class FlexSpringFactory implements FlexFactory { public FactoryInstance createFactoryInstance(String id, ConfigMap properties) { SpringFactoryInstance instance = new SpringFactoryInstance(this, id, properties); instance.setSource(properties.getPropertyAsString(SOURCE, instance.getId())); return instance; } public Object lookup(FactoryInstance inst) { SpringFactoryInstance factoryInstance = (SpringFactoryInstance) inst; return factoryInstance.lookup(); } public void initialize(String arg0, ConfigMap arg1) { } } public class SpringFactoryInstance extends FactoryInstance { public SpringFactoryInstance(FlexSpringFactory factory, String id, ConfigMap properties) { super(factory, id, properties); } 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(); throw e; } catch (BeansException bexc) { ServiceException e = new ServiceException(); throw e; } }
login.mxml
<?xml version="1.0" encoding="utf-8"?> <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="326" height="162" title="登录" horizontalAlign="center" verticalAlign="middle"> <mx:RemoteObject id="loginDao" destination="teacherDao"/> <mx:Script> <![CDATA[ import As.bean.Teacher; import mx.rpc.events.FaultEvent; import mx.managers.PopUpManager; import mx.rpc.events.ResultEvent; import mx.controls.Alert; public var userId:Label; public var userName:Label; public var sex:Label; public var birth:Label; public var department:Label; public var profession:Label; public var mobile:Label; public var teacher:Teacher; private function callRO(str:String,psw:String):void{ var t:Teacher=new Teacher(); t.loginname=str; t.loginpass=psw; loginDao.Login(t); loginDao.addEventListener(ResultEvent.RESULT,getROResult); loginDao.addEventListener(FaultEvent.FAULT,getError); } private function getError(e:FaultEvent):void{ Alert.show(e.message.toString()); } private function getROResult(e:ResultEvent) :void { if(e.result.loginname=="error"){ tip.text="No such user!! "; }else { teacher=e.result as Teacher; sex.text=e.result.sex; userId.text=e.result.id; userName.text=e.result.name; birth.text=e.result.birth; department.text=e.result.department; profession.text=e.result.profession; mobile.text=e.result.mobile; proccessLogin(); } } private function proccessLogin():void{ PopUpManager.removePopUp(this); } ]]> </mx:Script> <mx:Label x="34" y="33" text="用户"/> <mx:TextInput x="77" y="31" id="userNameTxt"/> <mx:Label x="34" y="61" text="密码"/> <mx:TextInput x="77" y="59" displayAsPassword="true" id="psw"/> <mx:Button x="77" y="90" label="登录" click="callRO(userNameTxt.text,psw.text);"/> <mx:Label x="163" y="94" id="tip" color="red"/> </mx:TitleWindow>
applicationcontext.xml
<bean id="TeacherDAO" class="com.source.bean.TeacherDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean>
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-10-21
服务器用的是什么
|
|
返回顶楼 | |
发表时间:2008-10-21
qintao1203 写道 服务器用的是什么
tomcat |
|
返回顶楼 | |
发表时间:2008-11-09
因为上次写少teacherDao这次加上!!
public class TeacherDAO extends HibernateDaoSupport { private static final Log log = LogFactory.getLog(TeacherDAO.class); protected void initDao() { // do nothing } public void save(Teacher transientInstance) { log.debug("saving Teacher instance"); try { getHibernateTemplate().save(transientInstance); log.debug("save successful"); } catch (RuntimeException re) { log.error("save failed", re); throw re; } } public void delete(Teacher persistentInstance) { log.debug("deleting Teacher instance"); try { getHibernateTemplate().delete(persistentInstance); log.debug("delete successful"); } catch (RuntimeException re) { log.error("delete failed", re); throw re; } } public Teacher findById(java.lang.Integer id) { log.debug("getting Teacher instance with id: " + id); try { Teacher instance = (Teacher) getHibernateTemplate().get( "com.source.bean.Teacher", id); return instance; } catch (RuntimeException re) { log.error("get failed", re); throw re; } } public List findByExample(Teacher instance) { log.debug("finding Teacher instance by example"); try { List results = getHibernateTemplate().findByExample(instance); log.debug("find by example successful, result size: " + results.size()); return results; } catch (RuntimeException re) { log.error("find by example failed", re); throw re; } } public List findByProperty(String propertyName, Object value) { log.debug("finding Teacher instance with property: " + propertyName + ", value: " + value); try { String queryString = "from Teacher as model where model." + propertyName + "= ?"; return getHibernateTemplate().find(queryString, value); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } } public List findAll() { log.debug("finding all Teacher instances"); try { String queryString = "from Teacher"; return getHibernateTemplate().find(queryString); } catch (RuntimeException re) { log.error("find all failed", re); throw re; } } public Teacher merge(Teacher detachedInstance) { log.debug("merging Teacher instance"); try { Teacher result = (Teacher) getHibernateTemplate().merge( detachedInstance); log.debug("merge successful"); return result; } catch (RuntimeException re) { log.error("merge failed", re); throw re; } } public void attachDirty(Teacher instance) { log.debug("attaching dirty Teacher instance"); try { getHibernateTemplate().saveOrUpdate(instance); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } public void attachClean(Teacher instance) { log.debug("attaching clean Teacher instance"); try { getHibernateTemplate().lock(instance, LockMode.NONE); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } public static TeacherDAO getFromApplicationContext(ApplicationContext ctx) { return (TeacherDAO) ctx.getBean("TeacherDAO"); } } |
|
返回顶楼 | |
发表时间:2008-11-12
博主,请给我这个小例子的源码好么,最近小弟也是在整合的时候出现了AOP注入导致,Java脱离spring管理的问题。。。狂郁闷中。
|
|
返回顶楼 | |
发表时间:2008-11-12
请问下
注册sping factory, 修改WEB-INF\flex配置 <factory id="springFactory" class="cn.org.coral.core.flex.factory.FlexSpringFactory" /> 是修改 WEB-INF\flex 目录下的哪个 XML 文件??? |
|
返回顶楼 | |
发表时间:2008-11-12
注册sping factory, 修改WEB-INF\flex配置 <factory id="springFactory" class="cn.org.coral.core.flex.factory.FlexSpringFactory" /> |
|
返回顶楼 | |
发表时间:2008-11-12
在这个文件services-config.xml注册
|
|
返回顶楼 | |
发表时间:2009-02-09
继承FlexFactory需要载入什么jar文件吗
|
|
返回顶楼 | |
发表时间:2009-02-09
import flex.messaging.FactoryInstance;
import flex.messaging.FlexFactory; import flex.messaging.config.ConfigMap; 是这三个,请问都是在什么包里的 |
|
返回顶楼 | |