Webwork项目总结一(转)
最近在做一个WEBWORK的项目.总体感觉比T要方便\简单\明了好多....[同事总结的,工作忙我都没时间写]
做了些总结:
一.项目结构
1.项目结构:webwork+hibernate(3)+spring+freemarker
二.项目细节
1.xwork.xml...作为WEBWORK的配置文件.
最好是将分项目都分别写到单独的xwork-*.xml的配置文件中.
这样方便管理和维护.思路也很清晰.
2.自己编写基类继承HibernateDaoSupport.使用自己的基类,如果要脱离Spring时,只要将HibernateDaoSupport改掉就好了.
说点题外话.记得以前用hibernate都是直接用的。那个时候spring还没有用起来.呵呵。感觉现在封装起来挺好的哈,很方便.

三.hibernate总结
1.更新属性
*获得对象
*设置此对象的setPro方法,设置需要修改的属性值
*利用hibernate相关对象更新此并保存对象.
Enity Enity = (Enity) super.loadById(Enity.class,Id);
Enity.setName(newName);
return super.update(Enity);
2.简单的HQL语句
- Session session = sessionFactory.openSession();
- Transaction tx = session.beginTransaction();
- String hqlUpdate = "update Customer set name = :newName";
- int updatedEntities = s.createQuery( hqlUpdate )
- .setString( "newName", newName )
- .executeUpdate();
- tx.commit();
- session.close();
3.
public boolean deleteCommentById(long Id){
int exInt = super.getSession().createSQLQuery("delete Comment comm from comm.cmtedId=:Id").setLong("Id",Id).executeUpdate();
if(exInt>0){
return true;
}
return false;
}
三.与spring结合
HibernateTemplate提供持久层访问模板化,使用HibernateTemplate无须实现特定接口,它只需要提供一个SessionFactory的引用,就可执行持久化操作。SessionFactoyr对象可通过构造参数传入,或通过设值方式传入。
对于在Web应用,通常启动时自动加载ApplicationContext,SessionFactory和DAO对象都处在Spring上下文管理下,因此无须在代码中显式设置,可采用依赖注入解耦SessionFactory和DAO,依赖关系通过配置文件来设置,如下所示:
看我的Webwork项目总结二...嘿嘿....
lunzi
2007-06-21 19:35:16
评论:0
阅读:368
引用:0
