| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1593 人关注过本帖
标题:ssh框架 求BaseDao代码
取消只看楼主 加入收藏
蓝色石头
Rank: 2
等 级:论坛游民
帖 子:13
专家分:70
注 册:2009-9-17
结帖率:0
收藏
已结贴  问题点数:0 回复次数:1 
ssh框架 求BaseDao代码
刚刚开始搭建架构.以前代码没有带.求BaseDao代码以做参考!

今天下午没人回.我自己来回复
搜索更多相关主题的帖子: 搭建 架构 
2011-04-07 13:12
蓝色石头
Rank: 2
等 级:论坛游民
帖 子:13
专家分:70
注 册:2009-9-17
收藏
得分:0 
哎。。弄出来了
==============================================
package com.cls.dao;

public interface BaseDao<T,S> {
    public void save(T entity);

    public void deleteById(S PK);

    public void delete(T entity);
   
    public void update(T entity);
   
    public T findById(S PK);
}
===============================================
package com.cls.daoimpl;

import

import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import sun.security.action.GetBooleanAction;

import com.cls.dao.BaseDao;

public class BaseDaoImpl<T, S extends Serializable> implements BaseDao<T, S> {

    protected Class entityClass;
    private SessionFactory sessionFactory;
    ApplicationContext apc = new FileSystemXmlApplicationContext(
            "/WEB-INF/classes/applicationContext.xml");

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = (SessionFactory) apc.getBean("sessionFactory");
    }

    public void delete(T entity) {
        Session session = sessionFactory.openSession();
        Transaction tx = session.beginTransaction();
        session.delete(entity);
        session.close();
        ();
    }

    public void deleteById(S PK) {
        Session session = sessionFactory.openSession();
        Transaction tx = session.beginTransaction();
        T t = (T) session.get(this.entityClass, PK);
        session.delete(t);
        ();
    }

    public T findById(S PK) {
        Session session = sessionFactory.openSession();
        Transaction tx = session.beginTransaction();
        T t = (T) session.get(this.entityClass, PK);
        return t;
    }

    public void save(T entity) {
        Session session = sessionFactory.openSession();
        Transaction tx = session.beginTransaction();
        session.save(entity);
        ();
    }

    public void update(T entity) {
        Session session = sessionFactory.openSession();
        Transaction tx = session.beginTransaction();
        session.update(entity);
        ();
    }

}
====================================================
2011-04-08 15:50
快速回复:ssh框架 求BaseDao代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018864 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved