class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
org.hibernate.dialect.Oracle9Dialect
cn/com/jobedu/shop/model/Catalog.hbm.xml
5.通过MyEclipse的向导方式,生成POJO类和对应的映射文件。
6.修改applicationContext.xml文件中元素的内容。
如下所示:
cn/com/jobedu/shop/model/Catalog.hbm.xml
cn/com/jobedu/shop/model/Product.hbm.xml
7.编写DAO接口。
package.jobedu.shop.dao;
importjava.util.List;
import.jobedu.shop.model.Catalog;
publicinterfaceCatalogDao{
publicvoidcreate(Catalogc);
publicCataloggetCatalog(Longid);
publicListgetCatalogs();
publicvoidupdate(Catalogc);
publicvoidremove(Longid);
}
8.编写DAO接口的实现类,实现类使用Spring提供的帮助类。
示意如下:
package.jobedu.shop.dao.hibernate;
importjava.util.List;
importorg.springframework.orm.hibernate3.support.HibernateDaoSupport;
import.jobedu.shop.dao.CatalogDao;
import.jobedu.shop.model.Catalog;
publicclassCatalogDaoHibernateextendsHibernateDaoSupportimplementsCatalogDao{
@Override
publicvoidcreate(Catalogc){
//HibernateTemplatetemplate=getHibernateTemplate();
//template.save(c);
getHibernateTemplate().save(c);
}
@Override
publicCataloggetCatalog(Longid){
return(Catalog)getHibernateTemplate().get(Catalog.class,id);
}
@Override
publicListgetCatalogs(){
returngetHibernateTemplate().find("fromCatalogorderbyiddesc");
}
@Override
publicvoidremove(Longid){
//Catalogc=this.getCatalog(id);
//getHibernateTemplate().delete(c);
getHibernateTemplate().delete(getCatalog(id));
}
@Override
publicvoidupdate(Catalogc){
getHibernateTemplate().update(c);
}
}
9.修改applicationContext.xml文件,增加对Dao实现类的配置。
class=".jobedu.shop.dao.hibernate.CatalogDaoHibernate">
1.2在组合Struts2,完成Struts2、Spring和Hibernate的三者组合
1.修改web.xml文件,增加struts2的所需要的过滤器配置。
struts2
org.apache.struts2.dispatcher.FilterDispatcher
struts2
/*
1.增加Struts2相应类库,增加struts2-spring-plugin-x-x-x.jar文件。
(Struts的压缩包中,Struts所提供的。
)
2.需要拷贝struts.xml文件到src跟目录下,再修改struts.xml文件,进行常量配置。
3.修改web.xml文件,配置Spring监听器和上下文变量。
contextConfigLocation
/WEB-INF/applicationContext*.xml
org.springframework.web.context.ContextLoaderListener
4.编写Action类。
5.配置Struts.xml文件。
struts.xml
DOCTYPEstrutsPUBLIC
"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.0//EN"
"http:
//struts.apache.org/dtds/struts-2.0.dtd">
hello.jsp
....
6.修改applicationConext.xml,默认情况下,Spring从下面的文件中寻找为action所做的配置。
xmlversion="1.0"encoding="UTF-8"?
>
...
7.编写所需要的JSP文件。
8.部署,调试整个项目。