flex学习笔记.docx

上传人:b****5 文档编号:7478463 上传时间:2023-01-24 格式:DOCX 页数:66 大小:1.15MB
下载 相关 举报
flex学习笔记.docx_第1页
第1页 / 共66页
flex学习笔记.docx_第2页
第2页 / 共66页
flex学习笔记.docx_第3页
第3页 / 共66页
flex学习笔记.docx_第4页
第4页 / 共66页
flex学习笔记.docx_第5页
第5页 / 共66页
点击查看更多>>
下载资源
资源描述

flex学习笔记.docx

《flex学习笔记.docx》由会员分享,可在线阅读,更多相关《flex学习笔记.docx(66页珍藏版)》请在冰豆网上搜索。

flex学习笔记.docx

flex学习笔记

Flex4.5+BlazeDS+Spring3+Hibernate3.3开发环境搭建

Author:

tjx

CreateTime:

2012-2-28

所需软件

1、MyEclipse9

2、FlashBuild4.5

3、blazeds-turnkey-4.0.1.21287

4、Tomcat6

5、MySql5.5

搭建开发环境详细步骤

搭建web工程

1、新建一个flexServer的web工程

弹出对话框,输入工程名flexServer,选J2EE6.0,点击完成按钮。

就生成了一个web工程项目

2、加入spring3.0

在项目上点击右键,MyEclipseAddspring…

弹出对话框,选择相关spring包,包括:

Spring3.0AOPLibraries

Spring3.0JDBCLibraries

Spring3.0J2EELibraries

Spring3.0RemotingLibraries(BlazeDB需要用到)

Spring3.0WEBLibraries

选择把包拷贝到WEB-INF/lib目录下

点击下一步,选择spring配置文件放置的路径

点击完成按钮。

在web.xml中加入以下配置

contextConfigLocation

/WEB-INF/applicationContext.xml

org.springframework.web.context.ContextLoaderListener

3、在MyEclipse中连接数据库

选择窗口显示视图其它

弹出窗口

如图选择DBBrowser点击确定

就会出现如下窗口

在上面点击右键

选择New…新建数据库连接,配置好驱动以及各种连接参数

可以点击TestDriver测试一下连接,点击完成。

窗口上就多了一个数据库的图标

双击或是点右键打开连接,弹出新窗口

输入密码点击确定。

数据库连接成功,如下图,就可以查看数据库里的信息

4、加入hibernate3.3

如上图选择AddHibernateCapabilities…

如图选上hibernate包,并选择放在WEB-INF/lib目录下。

点击下一步。

选择由spring管理hibernate配置文件。

点击下一步

如图,点击下一步。

选择前面建好的数据库连接flexDB,参数自动填入,输入密码,点击下一步

如图去掉打勾。

不建立单独的SessionFactory类,交给Spring管理,点击完成。

5、运用hibernate生成PO类、xml映射文件和DAO文件

先建立工程目录。

如上图:

po包存放实体类和hbm配置文件;dao包放置dao接口和实现类;service包放置业务层的服务类接口和实现类。

点击MyEclipse的右上角图标

,如下图

选择MyEclipseDatabaseExplorer,左边窗口出现DBBrowser窗口,

选择所有表

如上图,选择HibernateReverseEngineering

选择好工程目录,把pojo类和bhm.xml文件建在po目录下,点击下一步。

由于数据库是MySql,而且设计主键是自增长,因此选择”increment”。

点击完成。

在src/com/sm/po/的目录下就生成了如上图的实体类和hbm.xml文件。

再重复以上操作生成dao

点击下一步

点击完成。

Dao就生成在com.sm.dao.impl目录下。

由于dao和实体类不在一个目录,因此dao里的实体类需要从新引用新的路径。

就不会报错了。

在applicationContext.xml文件中的配置如下:

xmlversion=“1.0”encoding=“UTF-8”?

>

xmlns=“http:

//www.springframework.org/schema/beans”

xmlns:

xsi=“http:

//www.w3.org/2001/XMLSchema-instance”

xmlns:

p=“http:

//www.springframework.org/schema/p”

xsi:

schemaLocation=“http:

//www.springframework.org/schema/beanshttp:

//www.springframework.org/schema/beans/spring-beans-3.0.xsd”>

 

class=“mons.dbcp.BasicDataSource”>

value=“com.mysql.jdbc.Driver”>

value=“jdbc:

mysql:

//192.168.1.93:

3306/edudb”>

class=“org.springframework.orm.hibernate3.LocalSessionFactoryBean”>

org.hibernate.dialect.MySQLDialect

com/sm/po/EduSubject.hbm.xml

com/sm/po/Demotree.hbm.xml

com/sm/po/EduAdminrole.hbm.xml

com/sm/po/EduExamitem.hbm.xml

com/sm/po/EduGrade.hbm.xml

com/sm/po/EduResolve.hbm.xml

com/sm/po/EduPaperedition.hbm.xml

com/sm/po/EduSubjectitem.hbm.xml

com/sm/po/EduExamandpaper.hbm.xml

com/sm/po/EduExam.hbm.xml

com/sm/po/EduExaminfo.hbm.xml

com/sm/po/EduExampaper.hbm.xml

com/sm/po/EduPaperchapter.hbm.xml

com/sm/po/EduQuicklinks.hbm.xml

com/sm/po/EduPapertype.hbm.xml

com/sm/po/EduAdminlog.hbm.xml

com/sm/po/EduExampoint.hbm.xml

com/sm/po/EduAdmin.hbm.xml

class=“com.sm.dao.impl.EduExamandpaperDAO”>

class=“com.sm.dao.impl.EduPapereditionDAO”>

class=“com.sm.dao.impl.EduExampointDAO”>

class=“com.sm.dao.impl.EduPaperchapterDAO”>

class=“com.sm.dao.impl.EduSubjectitemDAO”>

class=“com.sm.dao.impl.EduQuicklinksDAO”>

class=“com.sm.dao.impl.EduPapertypeDAO”>

class=“com.sm.dao.impl.EduExampaperDAO”>

class=“com.sm.dao.impl.EduAdminroleDAO”>

在com.sm.dao目录下写接口。

再让com.sm.dao.impl下的dao实现。

比如EduAdminDAO是DAO实现类,在com.sm.dao目录下写个IEduAdminDAO接口,再让EduAdminDAO实现这个接口。

 

到此为止J2EE的服务端spring和hibernate的整合已经基本完成,为了适用企业级的开发,还需完善几个方面:

1)配置连接池;2)配置spring管理事物;3)配置log4j;4)拆分applicationContext.xml文件。

6、配置连接池

配置C3P0连接池。

首先下载c3p0驱动包放在WEB-INF/lib下,并导入工程。

在applicationContext.xml文件的dataSource部分进行修改

这是原来的配置:

class=“mons.dbcp.BasicDataSource”>

value=“com.mysql.jdbc.Driver”>

value=“jdbc:

mysql:

//192.168.1.93:

3306/edudb”>

修改后:

mysql:

//192.168.1.93:

3306/edudb”>

--初始连接数-->

10

—最少连接数-->

5

—最大连接数-->

50

连接池还有其它一些属性可以设置,有兴趣自己研究,这里是基本设置。

在sessionFactory部分可以增加一些设置,便于开发。

class=“org.springframework.orm.hibernate3.LocalSessionFactoryBean”>

org.hibernate.dialect.MySQLDialect

—控制台输出sql语句-->

true

—sql语句格式化-->

true

--

80

35

-->

com/sm/po/EduSubject.hbm.xml

com/sm/po/Demotree.hbm.xml

com/sm/po/EduAdminrole.hbm.xml

com/sm/po/EduExamitem.hbm.xml

com/sm/po/EduGrade.hbm.xml

com/sm/po/EduResolve.hbm.xml

com/sm/po/EduPaperedition.hbm.xml

com/sm/po/EduSubjectitem.hbm.xml

com/sm/po/EduExamandpaper.hbm.xml

com/sm/po/EduExam.hbm.xml

com/sm/po/EduExaminfo.hbm.xml

com/sm/po/EduExampaper.hbm.xml

com/sm/po/EduPaperchapter.hbm.xml

com/sm/po/EduQuicklinks.hbm.xml

com/sm/po/EduPapertype.hbm.xml

com/sm/po/EduAdminlog.hbm.xml

com/sm/po/EduExampoint.hbm.xml

com/sm/po/EduAdmin.hbm.xml

7、配置spring事物管理

配置spring事务管理有很多种,这里使用aop:

config配置方式。

首先在applicationContext.xml文件中声明命名空间

xmlns:

aop=“http:

//www.springframework.org/schema/aop”

xmlns:

tx=“http:

//www.springframework.org/schema/tx”

在xsi:

s

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 成人教育 > 专升本

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1