EXT3.0
- 格式:pdf
- 大小:758.16 KB
- 文档页数:18
Struts2.1.6+Spring2.5+Hibernate3.3+
EXT3.0 简单教程
1. 数据库设计 Demo表(demo)
Filed Type Primary Index Description
id Int √ 主键,自增
C_name Varchar(500) 名称
CAS varchar(60) CAS编号
C_alias varchar(60) 别名
2. 后台设计
此DEMO基于J2EE,采用了Struts2、Hibernate、Spring等开源框架。需要
的Jar包如下图所示:
此DEMO在MyEclipse下的目录结构如下图所示:
先介绍src目录,com.struts2.filter包中存放的是Struts2的默认拦截器;
Log4j.properties文件是整个工程日志的配置;
Struts.xml文件是struts基本信息设置,可以用struts.properties取代;
Struts-ext.xml文件存放的是DEMO用到的Action的配置信息;
下面的3个是系统所依赖的类库;
下面是WebRoot目录:
Css目录存放的是工程依赖的css文件;
Ext3目录存放的是ExtJs3.0的js文件以及相关资源文件;
Images目录存放的是工程需要的图片;
Js目录存放的是工程依赖的javascript文件;
META-INF目录,暂时用不到;
WEB-INF目录,这个目录是比较重要的,下面对其详细介绍:
Lib目录,存放工程依赖的第三方jar文件;
action-servlet.xml , applicationContext-dao.xml ,
applicationContext-hibernate.xml , applicationContext-service.xml这4
个
XML文件是Spring的配置文件,Spring本来就只有一个配置文件,即
applicationContext.xml,这里将其拆分成4个文件,其目的是把业务Bean,
数据操作Bean,底层Bean,Action等等分开。action-servlet.xml主要是配置
Struts2的Action;applicationContext-dao.xml主要是配置DAO;
applicationContext-hibernate.xml主要是数据源,Hibernate的SessionFactory
以及Spring的声明式事务;applicationContext-service.xml配置业务Bean;
applicationContext-hibernate.xml的代码如下:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
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/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
value="net.sourceforge.jtds.jdbc.Driver" />
value="jdbc:jtds:sqlserver://localhost:1433/ext_demo" />
批注 [z1]: Schema方式的声明
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean
">
ext/demo/hbm/Demo.hbm.xml
org.hibernate.dialect.SQLServerDialect
class="org.springframework.orm.hibernate3.HibernateTransactionMan
ager">
class="org.springframework.transaction.interceptor.TransactionInt
erceptor">
ref="transactionManager">
PROPAGATION_REQUIRED 批注 [z2]: 配置数据源,这里采用的
是c3p0方式的数据源。
批注 [z3]: Hibernate的
SessionFactory
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED,readOnly
PROPAGATION_REQUIRED,readOnly
PROPAGATION_REQUIRED,readOnly
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED,readOnly
class="org.springframework.aop.framework.autoproxy.BeanNameAutoPr
oxyCreator">
userService
transactionInterceptor
web.xml是web工程最重要的一个文件,其代码如下:
<
web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">