xsi="http:
//www.w3.org/2001/XMLSchema-instance"
xsi:
schemaLocation="
struts2
--SpringApplicationContext配置文件的路径,可使用通配符*,多个路径用,号分隔,此参数用于后面的Spring-Contextloader-->
contextConfigLocation
/WEB-INF/spring/*.xml
--著名CharacterEncodingfilter-->
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
--struts2滤镜配置 -->
struts2
org.apache.struts2.dispatcher.FilterDispatcher
struts2
/*
--SpringApplicationContext载入,必须-->
org.springframework.web.context.ContextLoaderListener
--Spring刷新Introspector防止内存泄露-->
org.springframework.web.util.IntrospectorCleanupListener
--session超时定义,单位为分钟-->
10
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
(2)Hibernate配置:
xmlversion="1.0"encoding="UTF-8"?
>
DOCTYPEhibernate-configurationPUBLIC
"-//Hibernate/HibernateConfigurationDTD3.0//EN"
"
—-数据库驱动类名称-->
oracle.jdbc.driver.OracleDriver
—-数据库用户名-->
MY
MY
—-数据库用户密码-->
MY
—-数据库连接字符串-->
jdbc:
oracle:
thin:
@localhost:
1521:
loon
org.hibernate.dialect.Oracle9Dialect
—-控制台是否输出SQL语句-->
true
(3)Spring基本配置:
配置文件应该在WEB-INF/spring/下面
xmlversion="1.0"encoding="UTF-8"?
>
DOCTYPEbeansPUBLIC"-//SPRING//DTDBEAN//EN""http:
//www.springframework.org/dtd/spring-beans.dtd">
—如果用的是XML配置文件,sessionFactory用这个配置"org.springframework.orm.hibernate3.LocalSessionFactoryBean"-->
classpath:
hibernate.cfg.xml
-- 配置多个hibernate.cfg.xml
classpath:
hibernate_admin1.cfg.xml
classpath:
hibernate_admin2.cfg.xml
-->
--Hibernate事务管理 -->
PROPAGATION_REQUIRED,readOnly
PROPAGATION_REQUIRED,-Exception
PROPAGATION_REQUIRED,-Exception
--
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED,readOnly
PROPAGATION_REQUIRED,readOnly
PROPAGATION_REQUIRES_NEW
-->
(4)struts.xml文件的配置:
DOCTYPEstrutsPUBLIC
"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.0//EN"
"http:
//struts.apache.org/dtds/struts-2.0.dtd">
/resource/json_struts2.jsp
/resource/json_struts2.jsp
3、 建立的项目目录:
Root:
/resource/ext2.0/ 将下载的ext-2.0-beta1.zip文件解压到该目录
/WEB-INF/web.xml
/WEB-INF/lib
/WEB-INF/classes/struts.xml
/WEB-INF/spring/applicationContext.xml
4、 代码清单:
Level.java
importjavax.persistence.Column;
importjavax.persistence.Entity;
importjavax.persistence.Id;
importjavax.persistence.Table;
@Entity
@Table(name="LOON_LEVEL")
publicclassLevelimplementsjava.io.Serializable{
privateLonglevelid;
privateStringlevelname;
privateStringdescription;
publicLevel(){
}
publicLevel(Longlevelid){
this.levelid=levelid;
}
publicLevel(Longlevelid,Stringlevelname,Stringdescription){
this.levelid=levelid;
this.levelname=levelname;
this.description=description;
}
@Id
@Column(name="LEVELID",unique=true,nullable=false,precision=5,scale=0)
publicLonggetLevelid(){
returnthis.levelid;
}
publicvoidsetLevelid(Longlevelid){
this.levelid=levelid;
}
@Column(name="LEVELNAME",length=64)
publicStringgetLevelname(){
returnthis.levelname;
}
publicvoidsetLevelname(Stringlevelname){
this.levelname=levelname;
}
@Column(name="DESCRIPTION",length=256)
publicStringgetDescription(){
returnthis.description;
}
publicvoidsetDescription(Stringdescription){
this.description=description;
}
}
ILevelDAO.java
importjava.util.List;
publicinterfaceILevelDAO{
publicLevelfindLevelById(Longid);
publicList findAllLevels();
publicvoidpersistLevel(Levellevel);
publicvoidremoveLevel(Levellevel);
publicvoidremoveById(Longid);
}
LevelDAO.java
importjava.util.List;
importorg.hibernate.Session;
importorg.springframework.orm.hibernate3.HibernateCallback;
importorg.springframework.orm.hibernate3.support.HibernateDaoSupport;
publicclassLevelDAOextendsHibernateDaoSupportimplementsILevelDAO{
publicLevelDAO(){
super();
}
publicLevelfindLevelById(Longid){
return(Level)getHibernateTemplate().get(Level.class,id);
}
publicListfindAllLevels(){
returngetHibernateTemplate().loadAll(Level.class);//.find("fromLevelo");//