数据库结构:
用户跟组织:多对对
用户跟角色:多对多
组织:有上级组织
资源跟组织:多对多
资源跟角色:多对多
资源:有上级资源
资源:有资源类型
BaseDaoImpl中用了Hibernate原生的session:
@Repository publicclass BaseDaoImpl<T> implements BaseDaoI<T> { @Autowired PRivate SessionFactory sessionFactory; /** * 获得当前事物的session * * @return org.hibernate.Session */ public Session getCurrentSession() { returnsessionFactory.getCurrentSession(); } @Override public T getByHql(String hql) { Query q = getCurrentSession().createQuery(hql); List<T> l = q.list(); if (l != null && l.size() > 0) { return l.get(0); } returnnull; } @Override public T getByHql(String hql, Map<String, Object> params) { Query q = getCurrentSession().createQuery(hql); if (params != null && !params.isEmpty()) { for (String key : params.keySet()) { q.setParameter(key, params.get(key)); } } List<T> l = q.list(); if (l != null && l.size() > 0) { return l.get(0); } returnnull; } @Override public Long count(String hql) { Query q = getCurrentSession().createQuery(hql); return (Long) q.uniqueResult(); } @Override public List<Map> findBySql(String sql) { SQLQuery q = getCurrentSession().createSQLQuery(sql); returnq.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list(); } |
BaseServiceImpl中有对泛型的处理:
@Service publicclass BaseServiceImpl<T> implements BaseServiceI<T> { @Autowired private BaseDaoI<T> baseDao; @Override public T getById(Serializable id) { Class<T> c = (Class<T>) ((ParameterizedType) getClass() .getGenericSuperclass()).getActualTypeArguments()[0]; returnbaseDao.getById(c, id); } @Override public T getByFilter(HqlFilter hqlFilter) { String className = ((Class<T>) ((ParameterizedType) getClass() .getGenericSuperclass()).getActualTypeArguments()[0]).getName() 学习交流
热门图片
猜你喜欢的新闻
新闻热点 2019-10-23 09:17:05
2019-10-21 09:20:02
2019-10-21 09:00:12
2019-09-26 08:57:12
2019-09-25 08:46:36
2019-09-25 08:15:43
疑难解答 |