[flex] 后台使用ibatis+spring 前台flex 基本的CRUD,前面一张简单的页面出不来。

惜宝三缘 2012-01-05
配置文件有三个:
flex—application-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:flex="http://www.springframework.org/schema/flex"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
                  http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
                  http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">

<!-- 加载message-broker服务的一种写法
<flex:message-broker id="_messageBroker"
services-config-path="WEB-INF/flex/services-config.xml">
<flex:mapping pattern="/messagebroker/*" /> 
<flex:exception-translator ref="myExceptionTranslator" /> 
</flex:message-broker>
-->

<!-- 加载message-broker服务-->
<bean id="_messageBroker"
class="org.springframework.flex.core.MessageBrokerFactoryBean">
<property name="servicesConfigPath"
value="WEB-INF/flex/services-config.xml" />
</bean>

<bean
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>/*=_messageBroker</value>
</property>
</bean>

<bean
class="org.springframework.flex.servlet.MessageBrokerHandlerAdapter">
</bean>

<!-- 以下的Bean可以直接被Flex客户端可访问RemoteObject-->
<bean name="docDao" class="doc.dao.impl.DocIBatisDaoImpl">
<property name="sqlMapClient" ref="sqlMapClient"/>
<flex:remoting-destination />
</bean>
</beans>


第二个是:spring-application-context.xml
<bean id="ds"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url"
value="jdbc:postgresql://localhost:5432/postgres" />
<property name="username" value="postgres" />
<property name="password" value="123" />
</bean>

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="SqlMapConfig.xml"/>
    <property name="dataSource" ref="ds"/>
</bean>
<bean name="docDao" class="doc.dao.impl.DocIBatisDaoImpl">
<property name="sqlMapClient" ref="sqlMapClient"/>

</bean>

sqlMapClient.xml


比较简单,
就一个页面,想得到所有的model,直接显示在list中


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" height="697" initialize="init()">
<mx:Panel x="90" y="89" width="498" height="341" layout="absolute">
<mx:List x="65" y="0" width="272" height="214" id="list"></mx:List>
</mx:Panel>


<mx:Script>
<![CDATA[
import mx.rpc.AbstractOperation;
import mx.utils.ArrayUtil;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import mx.rpc.remoting.RemoteObject;
import mx.collections.ArrayCollection;


private function init():void{
var remoteObject :RemoteObject = new RemoteObject();
remoteObject.destination = "docDao";
var operation :AbstractOperation = remoteObject.getOperation("getAll");
operation.addEventListener(ResultEvent.RESULT,resultHandler);
operation.addEventListener(FaultEvent.FAULT,faultHandler);
operation.send();
}

private function resultHandler(event:ResultEvent):void{
var array:ArrayCollection = event.result as ArrayCollection;
list.dataProvider = array[0];

}
private function faultHandler(event:FaultEvent):void{
Alert.show(event.message.toString());
}
]]>
</mx:Script>

</mx:Application>
Global site tag (gtag.js) - Google Analytics