package cn.th.work.dao.Impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import cn.th.work.dao.BaseDao;

@Repository
public  class BaseDaoImpl<T> extends SqlSessionDaoSupport implements BaseDao<T> {
	
	@Autowired
	public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){
		 super.setSqlSessionFactory(sqlSessionFactory);
	}
	
	//命名空间
	private String nameSpace;

	public String getNameSpace() {
		return nameSpace;
	}

	public void setNameSpace(String nameSpace) {
		this.nameSpace = nameSpace;
	}
	
	//主要业务
    
	//增
	public int save(T entity) {
		int num=0;
		num=this.getSqlSession().insert(nameSpace+".save",entity);
		return num;
	}

	//删一个
	public int deleteById(Serializable id) {
		int num=0;
		num=this.getSqlSession().delete(nameSpace+".deleteById",id);
		return num;
	}
    
	//批量删
	public void deletePart(Serializable[] ids) {
		
		this.getSqlSession().delete(nameSpace+".deletePart",ids);
	}
    
	//获得一个对象
	public T get(Serializable id) {
		
		return this.getSqlSession().selectOne(nameSpace+".get", id);
	}

	//改
	public int update(T entity) {
		int num=0;
		num=this.getSqlSession().update(nameSpace+".update",entity);
		return num;
	}

	//分页
	public List<T> getAll(Map map) {
		List<T> list=null;
		list=this.getSqlSession().selectList(nameSpace+".getAll",map);
		return list;
	}

	public int getCount(Map map) {
		int num=0;
		num=this.getSqlSession().selectOne(nameSpace+".getCount",map);
		return num;
	}

	
}
最近下载更多
zk1259  LV6 2024年8月22日
3334004690  LV10 2024年6月22日
zj20020510  LV5 2023年9月18日
renyuan  LV9 2022年12月7日
cx0127  LV13 2022年10月30日
testuser1234567  LV24 2022年6月30日
Zjy-0913  LV1 2022年6月11日
chasiubao  LV2 2022年6月9日
我是helloworld  LV23 2022年5月12日
lls0832  LV3 2022年5月3日
最近浏览更多
2022102154  LV1 3月27日
每天都要有长进 2024年10月25日
暂无贡献等级
zk1259  LV6 2024年8月22日
樱花味小然子  LV5 2024年7月2日
lun123456 2024年6月23日
暂无贡献等级
3334004690  LV10 2024年6月22日
lxzlxzl  LV1 2024年6月21日
李落辰 2024年6月17日
暂无贡献等级
李俊雄  LV3 2024年5月8日
2131234536546  LV7 2024年3月31日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友