package com.ssh2.impl; import java.util.Iterator; import java.util.List; import javax.annotation.Resource; import org.hibernate.Query; import org.hibernate.SessionFactory; import org.springframework.transaction.annotation.Transactional; import com.ssh2.dao.UserDao; import com.ssh2.model.PageBean; import com.ssh2.model.User; @Transactional public class UserImpl implements UserDao{ @Resource private SessionFactory sessionFactory; public boolean login(User user) { Iterator<User> it; String hsql="from User u where u.username=? and u.password=?"; Query query = sessionFactory.getCurrentSession().createQuery(hsql); query.setString(0,user.getUsername()); query.setString(1, user.getPassword()); it = query.iterate(); if(it.hasNext()){ return true; }else{ return false; } } public void add(User user) { sessionFactory.getCurrentSession().save(user); } public List getUser() { return sessionFactory.getCurrentSession().createQuery("from User").list(); } public void delete(int id) { sessionFactory.getCurrentSession().delete( sessionFactory.getCurrentSession().get(User.class, id)); } public User getUser(int id) { return (User)sessionFactory.getCurrentSession().get(User.class, id); } public void update(User user) { sessionFactory.getCurrentSession().update(user); } /** * 查询所有记录 */ public int getAllRowCount(String hql) { int allRow = sessionFactory.getCurrentSession().createQuery(hql).list().size(); return allRow; } /** * 分页查询 */ public List queryForPag(String hql, int start, int size) { Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setFirstResult(start); query.setMaxResults(size); List list = query.list(); return list; } public PageBean queryForPage(int pageSize, int page) { String hql = "from User"; int allRow = this.getAllRowCount(hql); int totalPage = PageBean.countTotalPage(pageSize, allRow); int size = pageSize; int start = PageBean.countStart(pageSize, page); int currentPage = PageBean.countCurrentPage(page); List list = this.queryForPag(hql, start, size); PageBean pb = new PageBean(); pb.setAllRow(allRow); pb.setTotalPage(totalPage); pb.setCurrentPage(currentPage); pb.setList(list); pb.setPageSize(pageSize); pb.init(); return pb; } }

ming_123_9715 LV23
2022年12月14日
PaymentCodeSystem LV11
2022年10月28日
gxlgxl LV4
2022年5月27日
漫长的白日梦 LV8
2021年12月4日
GD_chan LV5
2021年7月1日
lsglsg9 LV23
2021年1月7日
管子769431178 LV3
2020年6月6日
x1012786954 LV8
2020年6月4日
445507541 LV1
2020年6月2日
liwulong LV2
2020年5月19日

wanderingsoul LV2
2024年6月15日
微信网友_5986558820093952 LV4
2023年12月28日
lbsers LV5
2023年5月8日
3516569014 LV5
2023年5月7日
女王不该在山炮村养花 LV8
2023年4月13日
ming_123_9715 LV23
2022年12月13日
PaymentCodeSystem LV11
2022年10月28日
gxlgxl LV4
2022年5月27日
qqb123 LV8
2022年5月26日
阿达阿发爱国 LV1
2021年12月14日