package com.wgc.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.source.internal.SessionFactoryBuilderImpl;
import org.springframework.stereotype.Repository;

import com.wgc.entity.Dept;
import com.wgc.util.PageModel;
import com.wgc.util.SessionFactoryUtil;

@Repository("deptDao")
public class DeptDaoImpl extends SessionFactoryUtil implements DeptDao {


	@Override
	public Integer findCount() {
		Session session = this.sessionFactory.getCurrentSession();
		String sql = "select count(*) from Dept d";
		//return (Integer) session.createQuery(sql).uniqueResult();
		//数据库返回是长整形,需要转换
		Long count = (Long) session.createQuery(sql).uniqueResult();
		//intValue(),输出int数据。
		//用于浮点型表示去掉小数点
		return count.intValue();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Dept> selectDeptPage(PageModel pageModel) {
		Session session = this.sessionFactory.getCurrentSession();
		String sql = "select d from Dept d";
		return session.createQuery(sql)
				//开始数量
				.setFirstResult((pageModel.getPageIndex()-1)*pageModel.getPageSize())
				//每页显示数量
				.setMaxResults(pageModel.getPageSize())
				.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Dept> selectDeptByName(PageModel pageModel,String name) {
		Session session = this.sessionFactory.getCurrentSession();
		String sql = "select d from Dept d where d.name like '%"+name+"%'";
		System.out.println(sql.toString());
		return session.createQuery(sql)
				//开始数量
				.setFirstResult((pageModel.getPageIndex()-1)*pageModel.getPageSize())
				//每页显示数量
				.setMaxResults(pageModel.getPageSize())
				.list();
	}

	@Override
	public Integer findCountByName(String name) {
		Session session = this.sessionFactory.getCurrentSession();
		String sql = "select count(*) from Dept d where d.name like '%"+name+"%'";
		//return (Integer) session.createQuery(sql).uniqueResult();
		//数据库返回是长整形,需要转换
		Long count = (Long) session.createQuery(sql).uniqueResult();
		System.out.println("kk>>>>>>"+count);
		//intValue(),输出int数据。
		//用于浮点型表示去掉小数点
		return count.intValue();
	}

	//添加
	@Override
	public void addDept(Dept dept) {
		Session session = this.sessionFactory.getCurrentSession();
		session.persist(dept);
	}
	/****************修改*******************/
	@Override
	public Dept getDeptId(Integer id) {
		return (Dept) this.sessionFactory.getCurrentSession().get(Dept.class, id);
	}

	@Override
	public void updateDept(Dept dept) {
		this.sessionFactory.getCurrentSession().update(dept);
	}
	/****************修改*******************/
}
最近下载更多
程健飞  LV2 2023年3月30日
Hugo_0901  LV5 2022年4月27日
wanglinddad  LV55 2022年4月19日
wangzile1994  LV12 2022年4月16日
槛外人  LV6 2022年3月29日
afei115  LV4 2021年11月29日
864152530  LV5 2021年6月7日
zuihaofdfdfdfdddd  LV10 2021年5月30日
1207748096  LV6 2021年5月12日
and123456  LV11 2021年4月20日
最近浏览更多
黄志琴  LV1 前天
charies778 1月7日
暂无贡献等级
AOAO1234  LV2 2024年12月23日
asfsghjhgsfadaas 2024年12月16日
暂无贡献等级
isssssss7 2024年10月13日
暂无贡献等级
lqzixi  LV4 2024年10月9日
WBelong  LV8 2023年12月15日
zhangyanghao 2023年9月21日
暂无贡献等级
lcqlcl  LV11 2023年8月29日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友