在常规的开发中只是用flex二不和后台交互是不可能的,为此flex也提供了和后台交互的2种解决方案一种是Data Services另一种是BlazeDs,本篇博客是用的是后一种,我的开发步骤如下:

1.下载BlazeDs的war包,下载war包需要注册,下载地址如下:

https://www.adobe.com/cfusion/entitlement/index.cfm?e=lc_blazeds

2.解压或者部署war包,把WEB-INF下面的flex文件夹复制到项目的WEB-INF下面,把lib里面的所有jar包和目标项目合并

3.下载spring整合flex的jar包,下载地址是:

http://www.springsource.org/spring-flex/

下载好后把dist下面的jar包复制到项目的lib下面

4.编写处理后台数据的代码,java类也交给spring来处理,下面是我的xml配置文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
  6.  
  7. <bean id="flexPlanService" class="org.lxh.module.plan.flex.FlexPlanManagerImpl">
  8. <property name="planManager" ref="planManager"/>
  9. </bean>
  10. </beans>

5.编写spring和flex交互的主要配置文件,文件名称见名知义就行,配置大致如下

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:flex="http://www.springframework.org/schema/flex"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="
  6. http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  8. http://www.springframework.org/schema/flex
  9. http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">
  10.  
  11. <bean id="_messageBroker" class="org.springframework.flex.core.MessageBrokerFactoryBean" >
  12. <property name="servicesConfigPath" value="WEB-INF/flex/services-config.xml"/>
  13. </bean>
  14.  
  15. <!--spring mvc配置,所有请求都由_messageBroker处理-->
  16. <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  17. <property name="mappings">
  18. <value>/*=_messageBroker</value>
  19. </property>
  20. </bean>
  21. <bean class="org.springframework.flex.servlet.MessageBrokerHandlerAdapter"/>
  22.  
  23. <!-- destination-id是目标ID 这个名称在mxml页面上会被用到-->
  24. <flex:remoting-destination ref="flexPlanService" destination-id="flexPlanService"/>
  25.  
  26. </beans>

最后一行的ref熟悉就不介绍了,一般学过spring的都知道怎么用

6.在web.xml加入springmvc配置把上面的交互文件交给spring管理,配置如下

  1. <!-- SpringMVC配置 -->
  2. <servlet>
  3. <servlet-name>SpringDispatcher</servlet-name>
  4. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  5. <init-param>
  6. <param-name>contextConfigLocation</param-name>
  7. <param-value>classpath:applicationContext-flex.xml</param-value>
  8. </init-param>
  9. <load-on-startup>1</load-on-startup>
  10. </servlet>
  11. <servlet-mapping>
  12. <servlet-name>SpringDispatcher</servlet-name>
  13. <url-pattern>/messagebroker/*</url-pattern>
  14. </servlet-mapping>

7.给项目添加flex支持

(1)鼠标右击项目,找到Add Flex  project  type,如下所示

(2)在出现的窗口选择下一步,如下所示

(3)点击“下一步”进入下一个配置界面

需要注意的是Root folder,这里选择项目的根目录即可,选好后要注意点击“validate configuration”按钮验证配置,验证成功后,点击finish之后可能会报错,在problems里找到error,右键点击选择重建html-template即可

(4)这一步是可选的,一般我们把flex的main source folder换成别的

(5)这一步也是可选的,我们一般把webcontent或者webroot作为flex的输出目录

改动之后也是需要验证的,验证成功即可

8.编写flex页面,我这里只是简单的用表格显示出所有的部门信息,页面代码如下

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
  3. xmlns:s="library://ns.adobe.com/flex/spark"
  4. xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="300" minHeight="300" initialize="init()">
  5. <fx:Declarations>
  6. <!-- 这里的的destination对应spring配置文件里的destination-id-->
  7. <s:RemoteObject id="planServiceRO" destination="flexPlanService" endpoint="/myssm/messagebroker/amf">
  8. <!-- name对应的是bean里的接口方法 result配置的actionscript类似回调函数-->
  9. <s:method name="getAllPlan" result="getAllPlansSuccess(event)"/>
  10. </s:RemoteObject>
  11. </fx:Declarations>
  12. <fx:Script>
  13. <![CDATA[
  14.  
  15. import com.adobe.serialization.json.JSON
  16. import mx.collections.ArrayCollection;
  17. import mx.controls.Alert;
  18. import mx.core.FlexGlobals;
  19. import mx.events.FlexEvent;
  20. import mx.events.ListEvent;
  21. import mx.managers.PopUpManager;
  22. import mx.rpc.events.FaultEvent;
  23. import mx.rpc.events.ResultEvent;
  24. private function init():void{
  25.  
  26. planServiceRO.getAllPlan();
  27.  
  28. }
  29. //把数据绑定到表格里,数据类型使用的是json,此处需要一个叫as3corelib.swc的类库文件 ,把它放在libs目录里即可
  30. private function getAllPlansSuccess(event:ResultEvent):void{
  31. var planData:ArrayCollection=new ArrayCollection(com.adobe.serialization.json.JSON.decode(event.result.toString()));
  32. planDataGrid.dataProvider=planData;
  33. }
  34. ]]>
  35. </fx:Script>
  36. <mx:DataGrid id="planDataGrid" x="500" y="200" width="300" height="300"
  37. allowMultipleSelection="true" alternatingItemColors="[0xe3eaf2,0xe8f1f8]">
  38. <mx:columns>
  39. <!-- dataField属性配置的是json的key -->
  40. <mx:DataGridColumn dataField="fid" headerText="部门ID" showDataTips="true"/>
  41. <mx:DataGridColumn dataField="fname" headerText="部门名称" showDataTips="true"/>
  42.  
  43. </mx:columns>
  44. </mx:DataGrid>
  45. </s:Application>

下面我把自己的业务实现类代码贴出来,这个方法拼接了json字符串

  1. package org.lxh.module.plan.flex;
  2.  
  3. import java.util.*;
  4.  
  5. import org.lxh.module.plan.dao.PlanManager;
  6. import org.lxh.module.plan.info.PlanInfo;
  7.  
  8. public class FlexPlanManagerImpl implements FlexPlanManager {
  9. private PlanManager planManager;
  10. public PlanManager getPlanManager() {
  11. return planManager;
  12. }
  13. public void setPlanManager(PlanManager planManager) {
  14. this.planManager = planManager;
  15. }
  16. public String getAllPlan() {
  17. List<Map> json=new ArrayList<Map>();
  18. List<PlanInfo> all=planManager.getAllPlan();
  19. Iterator<PlanInfo> it=all.iterator();
  20. while(it.hasNext()){
  21. PlanInfo p=it.next();
  22. Map<String,Object> map=new HashMap<String,Object>();
  23. map.put("\"fid\"", "\""+p.getFID()+"\"");
  24. map.put("\"fname\"", "\""+p.getFNAME()+"\"");
  25. json.add(map);
  26. }
  27. return json.toString().replaceAll("=", ":");
  28. }
  29. }

只有学懂了spring要整合spring是不是很简单呢,来看下我的效果图

下面再把我的ibatis配置文件贴出来给大家看看

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="PlanInfo">
  5. <resultMap id="resultMap" type="org.lxh.module.plan.info.PlanInfo">
  6. <result property="fID" column="fID"/>
  7. <result property="fNAME" column="fNAME"/>
  8. </resultMap>
  9. <select id="getAllPlan" parameterType="org.lxh.module.plan.info.PlanInfo" resultMap="resultMap">
  10. select * from m_depart
  11. </select>
  12. </mapper>

下面是我oracle里的数据表

spring整合flex的更多相关文章

  1. Spring 整合 Flex (BlazeDS)无法从as对象 到 Java对象转换的异常:org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.Date' to required type 'java.sql.Timestamp' for property 'wfsj'; nested exception is java.lang.Ill

    异常信息如下: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value ...

  2. 1、Shiro 安全框架与Spring 整合详解

    Apache Shiro 是一个安全认证框架,和 Spring Security 相比,在于他使用了比较简洁易懂的认证和授权方式.其提供的 native-session(即把用户认证后的授权信息保存在 ...

  3. 使用Spring整合Quartz轻松完成定时任务

    一.背景 上次我们介绍了如何使用Spring Task进行完成定时任务的编写,这次我们使用Spring整合Quartz的方式来再一次实现定时任务的开发,以下奉上开发步骤及注意事项等. 二.开发环境及必 ...

  4. 【Java EE 学习 53】【Spring学习第五天】【Spring整合Hibernate】【Spring整合Hibernate、Struts2】【问题:整合hibernate之后事务不能回滚】

    一.Spring整合Hibernate 1.如果一个DAO 类继承了HibernateDaoSupport,只需要在spring配置文件中注入SessionFactory就可以了:如果一个DAO类没有 ...

  5. spring整合hibernate的详细步骤

    Spring整合hibernate需要整合些什么? 由IOC容器来生成hibernate的sessionFactory. 让hibernate使用spring的声明式事务 整合步骤: 加入hibern ...

  6. Spring整合Ehcache管理缓存

    前言 Ehcache 是一个成熟的缓存框架,你可以直接使用它来管理你的缓存. Spring 提供了对缓存功能的抽象:即允许绑定不同的缓存解决方案(如Ehcache),但本身不直接提供缓存功能的实现.它 ...

  7. spring整合hibernate

    spring整合hibernate包括三部分:hibernate的配置.hibernate核心对象交给spring管理.事务由AOP控制 好处: 由java代码进行配置,摆脱硬编码,连接数据库等信息更 ...

  8. MyBatis学习(四)MyBatis和Spring整合

    MyBatis和Spring整合 思路 1.让spring管理SqlSessionFactory 2.让spring管理mapper对象和dao. 使用spring和mybatis整合开发mapper ...

  9. Mybatis与Spring整合,使用了maven管理项目,作为初学者觉得不错,转载下来

    转载自:http://www.cnblogs.com/xdp-gacl/p/4271627.html 一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: mvn archetype ...

随机推荐

  1. ZOJ 2679 Old Bill(数学)

    主题链接:problemCode=2679" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProbl ...

  2. Android:自定义滚动边缘(EdgeEffect)效果

    Android可滚动控件(GridView.ListView.ScrollView等)当用户滚动到头的时候会有个边缘反馈效果,在4.0上默认为Holo蓝色效果.  如果您的App自定义了主题颜色,比如 ...

  3. Lucene.Net 2.3.1开发介绍 —— 三、索引(七)

    原文:Lucene.Net 2.3.1开发介绍 -- 三.索引(七) 5.IndexWriter 索引这部分最后讲的是IndexWriter.如果说前面提到的都是数据的结构,那么IndexWriter ...

  4. android中,如果使用imageButton可以在drawable 中设置一个selector,但是imageView设置不起作用

    android中,如果使用imageButton可以在drawable 中设置一个selector,但是imageView设置不起作用,只要把Imageview的src给去掉就成了,src捕获了bac ...

  5. discuz!代码内置颜色大全(收藏)

    加闪烁字:[light]文字[/light] 加文字特效:[shadow=255,red,2]文字[/shadow]: 在标签的中间插入文字可以实现文字阴影特效,shadow内属性依次为宽度.颜色和边 ...

  6. dumpbin

    在使用VC时,可以用DUMPBIN.EXE来得到某个DLL中所输出的符号的清单.如下面的 命令:dumpbin -exports Cmpnt1.dll如: C:/WINDOWS/system32> ...

  7. 为VisualSVN Server增加在线修改用户密码的功能

    原文:为VisualSVN Server增加在线修改用户密码的功能 附件下载:点击下载 VisualSVN Server是一个非常不错的SVN Server程序,方便,直观,用户管理也异常方便. 不过 ...

  8. timesten升级

    ttIsql "DSN=ttwind;UID=cacheuser;PWD=cacheuser;OraclePWD=cacheuser;" --1.查看当前版本号 Command&g ...

  9. Using Qt to build an Omi App for iOS (and Android)

    JUNE 6, 2014 / HHARTZ Working on projects where the technology is pre-determined, it's often difficu ...

  10. ThinkPHP中实例化对象M()和D()的区别,select和find的区别

    原文:ThinkPHP中实例化对象M()和D()的区别,select和find的区别 1.ThinkPHP中实例化对象M()和D()的区别 在实例化的过程中,经常使用D方法和M方法,这两个方法的区别在 ...