国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

SSH架構BaseDao實現

2019-11-15 00:34:07
字體:
來源:轉載
供稿:網友
SSH架構BaseDao實現
package cn.itcast.dao;import java.io.Serializable;import java.util.List;/** * BaseDao * @author Administrator * * @param <T> */public interface BaseDao<T> {    /**      * 保存一個對象      *       * @param o      * @return      */      public Serializable save(T o);        /**      * 刪除一個對象      *       * @param o      */      public void delete(T o);        /**      * 更新一個對象      *       * @param o      */      public void update(T o);        /**      * 保存或更新對象      *       * @param o      */      public void saveOrUpdate(T o);        /**      * 查詢      *       * @param hql      * @return      */      public List<T> find(String hql);        /**      * 查詢集合      *       * @param hql      * @param param      * @return      */      public List<T> find(String hql, Object[] param);        /**      * 查詢集合      *       * @param hql      * @param param      * @return      */      public List<T> find(String hql, List<Object> param);        /**      * 查詢集合(帶分頁)      *       * @param hql      * @param param      * @param page      *            查詢第幾頁      * @param rows      *            每頁顯示幾條記錄      * @return      */      public List<T> find(String hql, Object[] param, Integer page, Integer rows);        /**      * 查詢集合(帶分頁)      *       * @param hql      * @param param      * @param page      * @param rows      * @return      */      public List<T> find(String hql, List<Object> param, Integer page, Integer rows);        /**      * 獲得一個對象      *       * @param c      *            對象類型      * @param id      * @return Object      */      public T get(Class<T> c, Serializable id);        /**      * 獲得一個對象      *       * @param hql      * @param param      * @return Object      */      public T get(String hql, Object[] param);        /**      * 獲得一個對象      *       * @param hql      * @param param      * @return      */      public T get(String hql, List<Object> param);        /**      * select count(*) from 類      *       * @param hql      * @return      */      public Long count(String hql);        /**      * select count(*) from 類      *       * @param hql      * @param param      * @return      */      public Long count(String hql, Object[] param);        /**      * select count(*) from 類      *       * @param hql      * @param param      * @return      */      public Long count(String hql, List<Object> param);        /**      * 執行HQL語句      *       * @param hql      * @return 響應數目      */      public Integer executeHql(String hql);        /**      * 執行HQL語句      *       * @param hql      * @param param      * @return 響應數目      */      public Integer executeHql(String hql, Object[] param);        /**      * 執行HQL語句      *       * @param hql      * @param param      * @return      */      public Integer executeHql(String hql, List<Object> param);    }
package cn.itcast.daoImpl;import java.io.Serializable;import java.util.List;import org.hibernate.Query;import org.hibernate.session;import org.hibernate.SessionFactory;import org.sPRingframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Repository;import cn.itcast.dao.BaseDao;@Repository("BaseDAO")@SuppressWarnings("all")/** * BaseDaoImpl * @author Administrator * * @param <T> */public class BaseDaoImpl<T> implements BaseDao<T> {        private SessionFactory sessionFactory;        public SessionFactory getSessionFactory() {        return sessionFactory;    }    @Autowired    public void setSessionFactory(SessionFactory sessionFactory) {        this.sessionFactory = sessionFactory;    }    private Session getCurrentSession() {          return sessionFactory.getCurrentSession();      }        public Serializable save(T o) {        return this.getCurrentSession().save(o);    }    public void delete(T o) {        this.getCurrentSession().delete(o);    }    public void update(T o) {        this.getCurrentSession().update(o);    }    public void saveOrUpdate(T o) {        this.getCurrentSession().saveOrUpdate(o);    }    public List<T> find(String hql) {        return this.getCurrentSession().createQuery(hql).list();    }    public List<T> find(String hql, Object[] param) {        Query q = this.getCurrentSession().createQuery(hql);          if (param != null && param.length > 0) {              for (int i = 0; i < param.length; i++) {                  q.setParameter(i, param[i]);              }          }          return q.list();    }    public List<T> find(String hql, List<Object> param) {        Query q = this.getCurrentSession().createQuery(hql);          if (param != null && param.size() > 0) {              for (int i = 0; i < param.size(); i++) {                  q.setParameter(i, param.get(i));              }          }          return q.list();    }    public List<T> find(String hql, Object[] param, Integer page, Integer rows) {        if (page == null || page < 1) {              page = 1;          }          if (rows == null || rows < 1) {              rows = 10;          }          Query q = this.getCurrentSession().createQuery(hql);          if (param != null && param.length > 0) {              for (int i = 0; i < param.length; i++) {                  q.setParameter(i, param[i]);              }          }          return q.setFirstResult((page - 1) * rows).setMaxResults(rows).list();      }    public List<T> find(String hql, List<Object> param, Integer page,            Integer rows) {        if (page == null || page < 1) {              page = 1;          }          if (rows == null || rows < 1) {              rows = 10;          }          Query q = this.getCurrentSession().createQuery(hql);          if (param != null && param.size() > 0) {              for (int i = 0; i < param.size(); i++) {                  q.setParameter(i, param.get(i));              }          }          return q.setFirstResult((page - 1) * rows).setMaxResults(rows).list();    }    public T get(Class<T> c, Serializable id) {        return (T) this.getCurrentSession().get(c, id);    }    public T get(String hql, Object[] param) {        List<T> l = this.find(hql, param);          if (l != null && l.size() > 0) {              return l.get(0);          } else {              return null;          }    }    public T get(String hql, List<Object> param) {        List<T> l = this.find(hql, param);          if (l != null && l.size() > 0) {              return l.get(0);          } else {              return null;          }    }    public Long count(String hql) {        return (Long) this.getCurrentSession().createQuery(hql).uniqueResult();    }    public Long count(String hql, Object[] param) {        Query q = this.getCurrentSession().createQuery(hql);          if (param != null && param.length > 0) {              for (int i = 0; i < param.length; i++) {                  q.setParameter(i, param[i]);              }          }          return (Long) q.uniqueResult();    }    public Long count(String hql, List<Object> param) {        Query q = this.getCurrentSession().createQuery(hql);          if (param != null && param.size() > 0) {              for (int i = 0; i < param.size(); i++) {                  q.setParameter(i, param.get(i));              }          }          return (Long) q.uniqueResult();    }    public Integer executeHql(String hql) {        return this.getCurrentSession().createQuery(hql).executeUpdate();    }    public Integer executeHql(String hql, Object[] param) {        Query q = this.getCurrentSession().createQuery(hql);          if (param != null && param.length > 0) {              for (int i = 0; i < param.length; i++) {                  q.setParameter(i, param[i]);              }          }          return q.executeUpdate();      }    public Integer executeHql(String hql, List<Object> param) {        Query q = this.getCurrentSession().createQuery(hql);          if (param != null && param.size() > 0) {              for (int i = 0; i < param.size(); i++) {                  q.setParameter(i, param.get(i));              }          }          return q.executeUpdate();    }}
package cn.itcast.dao;import cn.itcast.entity.TEmail;/** * EmailDao * @author Administrator * */public interface TEmailDao {    public TEmail Login(String LoginName,String PassWord);        public TEmail FindByEmail(String param);        public Integer count(String param);        public void saveOrUpdate(TEmail T);        public void save(TEmail T);        public void update(TEmail T);        public TEmail get(Integer id);}
package cn.itcast.daoImpl;import cn.itcast.dao.BaseDao;import cn.itcast.dao.TEmailDao;import cn.itcast.entity.TEmail;/** * EmailDao實現類調用BaseDao實現EmailDao中的方法 * @author Administrator * */public class TEmailDaoImpl implements TEmailDao {    private BaseDao<TEmail> baseDao;        public BaseDao<TEmail> getBaseDao() {        return baseDao;    }    public void setBaseDao(BaseDao<TEmail> baseDao) {        this.baseDao = baseDao;    }    public TEmail Login(String LoginName,String Password) {        String hql="From TEmail where loginName=? and password=?";        return baseDao.get(hql, new Object[]{LoginName,Password});    }    public TEmail FindByEmail(String param) {        String hql="From TEmail where email=?";        return baseDao.get(hql, new Object[]{param});    }    public Integer count(String param) {        String hql="Select count(*) From TEmail where email=?";        Long s=baseDao.count(hql, new Object[]{param});        return s.intValue();    }        public void saveOrUpdate(TEmail T){        baseDao.saveOrUpdate(T);    }        public void save(TEmail T){        baseDao.save(T);    }        public void update(TEmail T){        baseDao.update(T);    }    public TEmail get(Integer id) {        return baseDao.get(TEmail.class, id);    }        }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 禹州市| 廊坊市| 靖宇县| 台东县| 鄂托克旗| 高雄市| 和平县| 景宁| 随州市| 九寨沟县| 张家界市| 墨玉县| 闻喜县| 霍州市| 宁安市| 朝阳县| 闽侯县| 金平| 富平县| 永福县| 五常市| 旬阳县| 南城县| 北票市| 海城市| 磐石市| 芜湖市| 南澳县| 新干县| 济源市| 兴业县| 贡觉县| 仁布县| 拜泉县| 个旧市| 苍山县| 永寿县| 墨竹工卡县| 襄城县| 准格尔旗| 准格尔旗|