加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

案例学习BlazeDS+Spring之九Company Manager

发布时间:2020-12-15 04:38:54 所属栏目:百科 来源:网络整理
导读:Company Manager 该DEMO与InSync是类似的,提供公司信息的CRUD操作。但CompanyManager使用注释来进行定义。也展示了对象关联(CompanyDAO类与IndustryDAO类有关联)的处理。 一、运行DEMO: 1、运行程序:http://localhost:8400/spring-flex-testdrive/compa

Company Manager

该DEMO与InSync是类似的,提供公司信息的CRUD操作。但CompanyManager使用注释来进行定义。也展示了对象关联(CompanyDAO类与IndustryDAO类有关联)的处理。


一、运行DEMO:
1、运行程序:http://localhost:8400/spring-flex-testdrive/companymgr/index.html;
2、在"Search"文本框输入几个字符,单击“Search”按钮,从数据库接收符合查找条件公司的信息。

3、单击“new Company”按钮,添加新的公司,填写信息后,保存。

二、理解代码:

1、companymgr.mxml:
有两个RemoteObject实例,一个连到companyService,一个连到industryService。
在程序初始化时,获取所有行业列表:roIndustry.findAll。返回的列表存在industries数组集当中,用于CompanyForm的industries属性。

2、CompanyForm.mxml:
该文件与InSync中的ContractForm差不多,但增加了BindableComboBox控件的绑定。BindableComboBox继承自ComboBox,它重写了设置dataProvider属性的方法,增加了对数据提供者COLLECTION_CHANGE的监听。

override public function set dataProvider(dataProvider:IList):void
??????? {
??????????? super.dataProvider = dataProvider;
??????????? dataProvider.addEventListener(CollectionEvent.COLLECTION_CHANGE,
??????????????? function(event:Event):void
??????????????? {
??????????????????? selectIndex();
??????????????? });
??????????? selectIndex();
??????? }

private function selectIndex():void
??????? {
??????????? if (!_value || !dataProvider)
??????????? {
??????????????? return;
??????????? }
??????????? for (var i:int = 0; i < dataProvider.length; i++)
??????????? {
??????????????? if (_value == dataProvider[i][valueField])
??????????????? {
??????????????????? selectedIndex = i;
??????????????????? return;
??????????????? }
??????????? }
??????? }

3、CompanyDAO和IndustryDAO主要使用annotations 来定义配置。

·org/springframework/flex/spring/samples/company/CompanyDAO.java
类定义前使用注释:
@Service("industryService") @Service注释表示定义一个bean
@RemotingDestination(channels = { "my-amf" }) 代表作为flex远程对象注解,等同于<flex:remoting-destination ref=“industryService” />


构造函数前使用注释:
@Autowired? Spring的注解,允许自动注入。“Spring 2.5 引入了 @Autowired 注释,它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作。”
CompanyDAO构造函数除了datasource参数,还有一IIndustryDAO参数,用于bean的构造器注入。 @Autowired 将分别寻找和它们类型匹配的Bean,将它们作为CompanyDAO(DataSource dataSource,IIndustryDAO industryDAO)的入参来创建CompanyDAO Bean。
@RemotingInclude 指出远程可见的方法

@RemotingExclude指出远程不可见的方法

4、IndustryDAO.java

这个类类似于CompanyDAO,使用注释来进行配置,IndustryDAO作为CompanyDAO构造函数的参数注入到CompanyDAO中,形成关联。

三、小结: CompanyDAO和IndustryDAO这两个bean并没有在app-config.xml中定义,也没有在flex-servlet.xml中暴露。它们在类定义中使用标注(@Service,@RemotingDestination,@Autowired,@RemotingInclude和@RemotingExclude)来配置。这个DEMO还展示对象关联(Company类有一个属性关联Industry类型)的用法。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读