设为首页 收藏本站
查看: 707|回复: 0

[经验分享] flex3+struts2+spring2+hibernate3+mysql(在web项目里面建flex,而不是flex工程)

[复制链接]

尚未签到

发表于 2016-10-24 08:47:04 | 显示全部楼层 |阅读模式
  贴几个重要的文件
  1。在原有的web项目中,添加flex步骤:
  首先,安装flex插件。详细见http://apps.hi.baidu.com/share/detail/20337120,只到安装即可。
  后面建工程就不要了。
  2。新建web工程,把struts2+spring2+hibernate3的所有包,和所有配置文件写好。(这个做web开发
  的都比较熟悉,在我的包里都有,就不说了)
  --------接下来就是添加flex了。
  右键点击工程名:如右图 DSC0000.jpg
  把flex工程加进去,在遇到新增完成的最后一步要记得取消“web.xml”那个选项。不然就覆盖了原来的web.xml了。
  3。把blazeds(是在tomcat/webapp/你的项目下,你安装flex插件后,建flex工程时,要用到blazeds.war这个文件,当你启动tomcat的时候会自动生成blazeds文件夹)里面的几个xml文件放到工程里面。如下图
DSC0001.jpg
  4。修改web-xml文件,加入如下:
  <!-- Http Flex Session attribute and binding listener support -->
 <listener>
  <listener-class>flex.messaging.HttpFlexSession</listener-class>
 </listener>
 <!-- MessageBroker Servlet -->
 <servlet>
        <servlet-name>MessageBrokerServlet</servlet-name>
           <servlet-class>
                flex.messaging.MessageBrokerServlet
        </servlet-class>
        <init-param>
                <param-name>
                        services.configuration.file
                </param-name>
                <param-value>
                        /WEB-INF/flex/services-config.xml
                </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
        <servlet-name>MessageBrokerServlet</servlet-name>
        <url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
  5。修改remoting-config.xml(配置flex访问java类的标记)和services-config.xml(配置swf访问路径)
  6。建立class文件,注意要有一个flex的映射文件以as结尾。
  7。修改mxml文件。我的文件如下:
  <?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  
               xmlns:locdg="com.flex.*" 
               creationComplete="initApp()"
               minWidth="955" minHeight="600"> 
<mx:RemoteObject id="goodsdata" destination="goodsDao" result="onResult(event)" fault="onFault(event)" ></mx:RemoteObject> 
<mx:RemoteObject id="addgoodsdata" destination="goodsDao" result="addResult(event)" fault="addFault(event)" /> 
<mx:RemoteObject id="deletegoodsdata" destination="goodsDao" result="deleteResult(event)" fault="deleteFault(event)" />
<mx:RemoteObject id="updategoodsdata" destination="goodsDao" result="updateResult(event)" fault="updateFault(event)" /> 
  <mx:Script>
 <![CDATA[
   import com.shop.flex.GoodsFlex;
   import com.shop.flex.DoubleClickDataGrid;
            import mx.collections.ArrayCollection; 
            import mx.controls.Alert; 
            import mx.managers.CursorManager; 
            import mx.rpc.events.FaultEvent; 
            import mx.rpc.events.ResultEvent;
           
            public var goodsFlex:GoodsFlex = new GoodsFlex(); 
            public var result:Object = new Object(); 
            [Bindable] 
            public var goods:ArrayCollection = new ArrayCollection();
            public function initApp():void{ 
           //   goodsdata.getGoodsList(); 
            }
            public function click_handler(event:Event):void{ 
                CursorManager.setBusyCursor(); 
                info.text = "正在查 询..."; 
                goodsdata.getGoodsList();   
            } 
 
            public function onResult(event:ResultEvent):void{ 
                goods = event.result as ArrayCollection; 
                CursorManager.removeBusyCursor(); 
                if(goods.length==0){ 
                    info.text="取数据成功,为空"; 
                    //Alert.show("取数据成功,为空");
                }else{ 
                    //info.text = " 取数据成功";
                     info.text = "取数据成功";
                } 
             } 
            public function onFault(event:FaultEvent):void{ 
                CursorManager.removeBusyCursor(); 
                info.text="取数据失败";
                 //Alert.show("取数据失败");
            }
           
            public function addgoods_handler(event:Event):void{ 
                if(goodsName.text != ""){ 
                    CursorManager.setBusyCursor(); 
                    goodsFlex.goodsName = goodsName.text; 
                    addgoodsdata.addGoods(goodsFlex); 
                }else{
                 addinfo.text = "没有填写数据";  
                } 
            }
            public function addResult(event:ResultEvent):void{ 
                CursorManager.removeBusyCursor(); 
                goodsdata.getGoodsList(); 
                goodsName.text = ""; 
                //Alert.show("添加成功");
                addinfo.text = "添加成功";
                //              info.text = "取数据成功"; 
            } 
            public function addFault(event:FaultEvent):void{ 
                CursorManager.removeBusyCursor(); 
                addinfo.text = "新增失败"; 
            }
  public function deleteGoods(event:Event):void{
    CursorManager.removeBusyCursor();
    goodsFlex.goodsId = goods_data.selectedItem.goodsId; 
                deletegoodsdata.deleteGoods(goodsFlex); 
   }
   
   public function deleteResult(event:ResultEvent):void{ 
                CursorManager.removeBusyCursor(); 
                goodsdata.getGoodsList();   
                //info.text = "刪除数据成 功"; 
            } 
            public function deleteFault(event:FaultEvent):void{ 
                CursorManager.removeBusyCursor(); 
                //info.text="刪除数据失败"; 
            }
           
             public function updateGoods(event:Event):void{ 
                if(goods_data.selectedItem.goodsName != ""){ 
                    CursorManager.setBusyCursor(); 
                    info.text = "正在 更新..."; 
                    goodsFlex.goodsId = goods_data.selectedItem.goodsId; 
                    goodsFlex.goodsName = goods_data.selectedItem.goodsName; 
                    updategoodsdata.updataGoods(goodsFlex); 
                } 
            }
           
             public function updateResult(event:ResultEvent):void{ 
                CursorManager.removeBusyCursor(); 
                goodsdata.getGoodsList();  
                info.text = "修改数据成功"; 
            } 
            public function updateFault(event:FaultEvent):void{ 
                CursorManager.removeBusyCursor(); 
                info.text="修改数据失败"; 
            }
  
  ]]>
</mx:Script>
 <mx:DataGrid dataProvider="{goods}" width="400" id="goods_data"
 fontSize="12" borderStyle="inset" fontWeight="bold" textAlign="center" alternatingItemColors="[#F1B6B6, #F2EB37]" height="210" editable="true">
   <mx:columns> 
     <mx:DataGridColumn headerText="ID号" dataField="goodsId" editable="false"/> 
             <mx:DataGridColumn headerText="账号" dataField="goodsName" editable="true"/>
            
             <mx:DataGridColumn headerText="修改" width="50" editable="false">
                 <mx:itemRenderer>
                  <mx:Component>
                   <mx:LinkButton toolTip="修改" click="outerDocument.updateGoods(event)" icon="@Embed('icon_06.gif')">    
                   </mx:LinkButton>
                  </mx:Component>
                 </mx:itemRenderer>
              
             </mx:DataGridColumn>
            
             <mx:DataGridColumn headerText="删除" width="50" editable="false">
                 <mx:itemRenderer>
                  <mx:Component>
                   <mx:LinkButton toolTip="删除" click="outerDocument.deleteGoods(event)" icon="@Embed('icon_03.gif')">    
                   </mx:LinkButton>
                  </mx:Component>
                 </mx:itemRenderer>
              
             </mx:DataGridColumn>
       </mx:columns>
    </mx:DataGrid>
    <mx:Button x="491" y="189" label="取数据" click="click_handler(event)" /> 
    <mx:Text x="606" y="189" id="info" text="点击按钮取数据"/> 
  <mx:Form x="163" y="72" borderStyle="solid" > 
        <mx:FormItem label="用户名" borderStyle="solid"> 
            <mx:TextInput id="goodsName" /> 
        </mx:FormItem> 
    </mx:Form> 
    <mx:Button x="444" y="100" label="添 加" click="addgoods_handler(event)"/>
    <mx:Text x="544" y="100" width="100" height="40" id="addinfo" text="请添加"/>
</mx:Application> 
实现了增删改查的所有功能。如下图
DSC0002.jpg
  我把工程放在文件下载里,lib比较大分4个rar放的,不明白联系QQ:654865674

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-290483-1-1.html 上篇帖子: MySQL Workbench建表时PK, NN, UQ, BIN, UN, ZF, AL的意思 下篇帖子: flex3+struts2+spring2+hibernate3+mysql(在web项目里面建flex,而不是flex工程)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表