实现用户操作接口:↓
package com.ssh02.daoimpl; import java.util.List; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import com.ssh02.dao.IUserDAO; import com.ssh02.model.UserEntity; import com.ssh02.util.Md5Util; @Transactional //纳入spring 容器管理 public class UserDAOImpl implements IUserDAO { //SessionFactory从spring 容器 取得Session @Autowired private SessionFactory sessionFactory; @Override public void save(UserEntity user){ user.setPass(Md5Util.md5s(user.getPass())); this.sessionFactory.getCurrentSession().save(user); } @Override public void delete(Integer id){ this.sessionFactory.getCurrentSession() .delete(this.sessionFactory.getCurrentSession().load(UserEntity.class, id)); } @Override public void update(UserEntity user){ if(user.getPass() != null)user.setPass(Md5Util.md5s(user.getPass())); this.sessionFactory.getCurrentSession().update(user); } @Override public UserEntity getUserById(Integer id){ return (UserEntity)this.sessionFactory.getCurrentSession().get(UserEntity.class, id); } @SuppressWarnings("unchecked") @Override public List<UserEntity> getUsers(Integer page,Integer size){ Integer start = (page-1)*size; return this.sessionFactory.getCurrentSession().createQuery("from UserEntity") .setFirstResult(start).setMaxResults(size).list(); } @Override public UserEntity getUserByIdName(String name, String pass) { pass = Md5Util.md5s(pass); return (UserEntity)this.sessionFactory.getCurrentSession() .createQuery("from UserEntity as user where user.name=:name and user.pass=:pass") .setString("name", name).setString("pass", pass).uniqueResult(); } @Override public Integer getUserCount() { String str = this.sessionFactory.getCurrentSession() .createQuery("select count(*) from UserEntity").uniqueResult().toString(); return Integer.valueOf(str); } }
实现角色接口:↓
package com.ssh02.daoimpl; import java.util.List; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import com.ssh02.dao.IGroupDAO; import com.ssh02.model.GroupEntity; @Transactional //纳入spring 容器管理 public class GroupDAOImpl implements IGroupDAO { //SessionFactory从spring 容器 取得Session @Autowired private SessionFactory sessionFactory; @Override public void save(GroupEntity group) { this.sessionFactory.getCurrentSession().save(group); } @Override public void delete(Integer id) { this.sessionFactory.getCurrentSession().delete(this.sessionFactory.getCurrentSession() .load(GroupEntity.class, id)); } @Override public void update(GroupEntity group) { this.sessionFactory.getCurrentSession().update(group); } @Override public GroupEntity getGroupById(Integer id) { return (GroupEntity)this.sessionFactory.getCurrentSession().get(GroupEntity.class, id); } @SuppressWarnings("unchecked") @Override public List<GroupEntity> getGroups(Integer page, Integer size) { Integer start = (page - 1)*size; return this.sessionFactory.getCurrentSession().createQuery("from GroupEntity") .setFirstResult(start).setMaxResults(size).list(); } @Override public Integer getGroupCount() { String str = this.sessionFactory.getCurrentSession() .createQuery("select count(*) from GroupEntity").uniqueResult().toString(); return Integer.valueOf(str); } }
实现权限接口:↓
package com.ssh02.daoimpl; 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.transaction.annotation.Transactional; import com.ssh02.dao.IAuthorityDAO; import com.ssh02.model.AuthorityEntity; @Transactional //纳入spring 容器管理 public class AuthorityDAOImpl implements IAuthorityDAO { //SessionFactory从spring 容器 取得Session @Autowired private SessionFactory sessionFactory; @Override public void save(AuthorityEntity authority) { this.sessionFactory.getCurrentSession().save(authority); } @Override public void delete(Integer id) { this.sessionFactory.getCurrentSession().delete(this.sessionFactory.getCurrentSession() .load(AuthorityEntity.class, id)); } @Override public void update(AuthorityEntity authority) { this.sessionFactory.getCurrentSession().update(authority); } @Override public AuthorityEntity getAuthorityById(Integer id) { return (AuthorityEntity)this.sessionFactory.getCurrentSession().get(AuthorityEntity.class, id); } @SuppressWarnings("unchecked") @Override public List<AuthorityEntity> getAuthoritys(Integer pid, Integer page, Integer size) { Integer start = (page - 1)*size; Session session = sessionFactory.getCurrentSession(); Query hql = session.createQuery("from AuthorityEntity as a where pid=:pid"); hql.setInteger("pid", pid); hql.setFirstResult(start); hql.setMaxResults(size); List<AuthorityEntity> alist = hql.list(); return alist; } @Override public Integer getAuthorityCount() { String str = this.sessionFactory.getCurrentSession().createQuery("select count(*) from AuthorityEntity") .uniqueResult().toString(); return Integer.valueOf(str); } }
实现商品分类操作接口:↓
package com.ssh02.daoimpl; 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.transaction.annotation.Transactional; import com.ssh02.dao.ICommodityClassDAO; import com.ssh02.model.CommodityClassEntity; @Transactional public class CommodityClassDAOImpl implements ICommodityClassDAO { @Autowired private SessionFactory sessionFactory; @Override public void save(CommodityClassEntity commodityclass) { this.sessionFactory.getCurrentSession().save(commodityclass); } @Override public void delete(Integer id) { this.sessionFactory.getCurrentSession().delete(this.sessionFactory.getCurrentSession() .load(CommodityClassEntity.class, id)); } @Override public void update(CommodityClassEntity commodityclass) { this.sessionFactory.getCurrentSession().update(commodityclass); } @Override public CommodityClassEntity getCommodityclassById(Integer id) { // TODO Auto-generated method stub return (CommodityClassEntity)this.sessionFactory.getCurrentSession().get(CommodityClassEntity.class, id); } @SuppressWarnings("unchecked") @Override public List<CommodityClassEntity> getCommodityclasss(Integer pid, Integer page, Integer size) { Integer start = (page - 1)*size; Session session = sessionFactory.getCurrentSession(); Query hql = session.createQuery("from CommodityClassEntity as a where pid=:pid"); hql.setInteger("pid", pid); hql.setFirstResult(start); hql.setMaxResults(size); List<CommodityClassEntity> alist = hql.list(); return alist; } @Override public Integer getCommodityclassCount() { String str = this.sessionFactory.getCurrentSession().createQuery("select count(*) from CommodityClassEntity") .uniqueResult().toString(); return Integer.valueOf(str); } }
实现商品列表操作接口:↓
package com.ssh02.daoimpl; 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.transaction.annotation.Transactional; import com.ssh02.dao.ICommodityDAO; import com.ssh02.model.CommodityEntity; @Transactional public class CommodityDAOImpl implements ICommodityDAO { @Autowired private SessionFactory sessionFactory; @Override public void save(CommodityEntity commodity) { this.sessionFactory.getCurrentSession().save(commodity); } @Override public void delete(Integer id) { this.sessionFactory.getCurrentSession().delete(this.sessionFactory.getCurrentSession() .load(CommodityEntity.class, id)); } @Override public void update(CommodityEntity commodity) { this.sessionFactory.getCurrentSession().update(commodity); } @Override public CommodityEntity getCommodityById(Integer id) { // TODO Auto-generated method stub return (CommodityEntity)this.sessionFactory.getCurrentSession().get(CommodityEntity.class, id); } @SuppressWarnings("unchecked") @Override public List<CommodityEntity> getCommoditys(Integer page, Integer size) { Integer start = (page - 1)*size; return this.sessionFactory.getCurrentSession().createQuery("from CommodityEntity") .setFirstResult(start).setMaxResults(size).list(); } @Override public Integer getCommodityCount() { String str = this.sessionFactory.getCurrentSession() .createQuery("select count(*) from CommodityEntity").uniqueResult().toString(); return Integer.valueOf(str); } @SuppressWarnings({"unchecked" }) @Override public List<CommodityEntity> getCommodityByCCId(Integer ccid) { Session session = this.sessionFactory.getCurrentSession(); String hql = "from CommodityEntity as c where c.commodityclass.id = :ccid"; Query query = session.createQuery(hql); query.setInteger("ccid", ccid); List<CommodityEntity> lists = query.list(); return lists; } }