package com.hx.common.service.impl; import com.hx.common.dao.CommonDao; import com.hx.mybatisTool.SqlSentence; import org.apache.ibatis.session.SqlSessionFactory; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.io.Serializable; import java.util.List; import java.util.Map; /**当前是没有事务处理,切勿直接使用*/ @Service public class CommonDaoImpl implements CommonDao { @Resource(name = "sqlSessionFactory") protected SqlSessionFactory sqlSessionFactory; /**组拼XML文件sql的id*/ private String getStatement(Class clazz, String prefix){ return clazz.getName()+"."+prefix; } /**插入*/ @Override public int insert(Class mapperClass,T entity) { return sqlSessionFactory.openSession().insert(getStatement(mapperClass,"insert"),entity); } /**获取条数 * @return*/ @Override public int selectCount(Class mapperClass, SqlSentence sqlSentence) { return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCount"),sqlSentence); } /**获取条数 * @return*/ @Override public int selectCountSql(Class mapperClass, SqlSentence sqlSentence) { return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCountSql"),sqlSentence); } /**获取列表*/ @Override public List selectList(Class mapperClass, SqlSentence sqlSentence) { return sqlSessionFactory.openSession().selectList(getStatement(mapperClass,"selectList"),sqlSentence); } /**获取列表*/ @Override public List> selectListMap(Class mapperClass, SqlSentence sqlSentence) { return sqlSessionFactory.openSession().selectList(getStatement(mapperClass,"selectListMap"),sqlSentence); } /**获取单条数据*/ @Override public T selectOne(Class mapperClass, SqlSentence sqlSentence) { return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOne"),sqlSentence); } /**获取单条数据*/ @Override public Map selectOneMap(Class mapperClass, SqlSentence sqlSentence) { return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneMap"),sqlSentence); } /**获取单条数据-不含longText的数据*/ @Override public T selectOneByKey(Class mapperClass,Object object) { return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneByKey"),object); } /**获取单条数据-含longText的数据*/ @Override public T selectOneByKeyBlob(Class mapperClass,Object object) { return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneByKeyBlob"),object); } /**更新*/ @Override public int updateWhere(Class mapperClass,SqlSentence sqlSentence) { return sqlSessionFactory.openSession().update(getStatement(mapperClass,"updateWhere"),sqlSentence); } /**全部字段更新*/ @Override public int updateAll(Class mapperClass,T entity) { return sqlSessionFactory.openSession().update(getStatement(mapperClass,"updateAll"),entity); } /**删除*/ @Override public int deleteWhere(Class mapperClass,SqlSentence sqlSentence) { return sqlSessionFactory.openSession().delete(getStatement(mapperClass,"deleteWhere"),sqlSentence); } /**删除*/ @Override public int deleteById(Class mapperClass,Object object) { return sqlSessionFactory.openSession().delete(getStatement(mapperClass,"deleteById"),object); } }