ChenJiaHe
2020-11-25 db7fc9f145beb76bbef19b1812d63d2ffc2d0df9
提交 | 用户 | age
3fde78 1 package com.hx.common.service.impl;
C 2
3 import com.hx.common.dao.CommonDao;
4 import com.hx.mybatisTool.SqlSentence;
5 import org.apache.ibatis.session.SqlSessionFactory;
6 import org.springframework.stereotype.Service;
7
8 import javax.annotation.Resource;
9 import java.io.Serializable;
10 import java.util.List;
11 import java.util.Map;
12
13 /**当前是没有事务处理,切勿直接使用*/
14 @Service
15 public class CommonDaoImpl implements CommonDao {
16
17     @Resource(name = "sqlSessionFactory")
18     protected SqlSessionFactory sqlSessionFactory;
19
20     /**组拼XML文件sql的id*/
21     private <T> String getStatement(Class<T> clazz, String prefix){
22         return clazz.getName()+"."+prefix;
23     }
24
25     /**插入*/
26     @Override
27     public <T extends Serializable> int insert(Class<?> mapperClass,T entity) {
28         return sqlSessionFactory.openSession().insert(getStatement(mapperClass,"insert"),entity);
29     }
30
31     /**获取条数*/
32     @Override
9338de 33     public <T extends Serializable> int selectCount(Class<?> mapperClass,SqlSentence sqlSentence) {
C 34         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCount"),sqlSentence);
3fde78 35     }
C 36
37     /**获取列表*/
38     @Override
39     public <T extends Serializable> List<T> selectList(Class<?> mapperClass, SqlSentence sqlSentence) {
40         return sqlSessionFactory.openSession().selectList(getStatement(mapperClass,"selectList"),sqlSentence);
41     }
42
43     /**获取列表*/
44     @Override
45     public <T extends Serializable> List<Map<String, Object>> selectListMap(Class<?> mapperClass, SqlSentence sqlSentence) {
46         return sqlSessionFactory.openSession().selectList(getStatement(mapperClass,"selectListMap"),sqlSentence);
47     }
48
49     /**获取单条数据*/
50     @Override
51     public <T extends Serializable> T selectOne(Class<?> mapperClass, SqlSentence sqlSentence) {
52         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOne"),sqlSentence);
53     }
54
55     /**获取单条数据*/
56     @Override
57     public <T extends Serializable> Map<String, Object> selectOneMap(Class<?> mapperClass, SqlSentence sqlSentence) {
58         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneMap"),sqlSentence);
59     }
60
61     /**获取单条数据-不含longText的数据*/
62     @Override
63     public <T extends Serializable> T selectOneByKey(Class<?> mapperClass,Object object) {
64         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneByKey"),object);
65     }
66
67     /**获取单条数据-含longText的数据*/
68     @Override
69     public <T extends Serializable> T selectOneByKeyBlob(Class<?> mapperClass,Object object) {
70         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneByKeyBlob"),object);
71     }
72
73     /**更新*/
74     @Override
9338de 75     public <T extends Serializable> int updateWhere(Class<?> mapperClass,SqlSentence sqlSentence) {
C 76         return sqlSessionFactory.openSession().update(getStatement(mapperClass,"updateWhere"),sqlSentence);
3fde78 77     }
C 78
79     /**全部字段更新*/
80     @Override
81     public <T extends Serializable> int updateAll(Class<?> mapperClass,T entity) {
82         return sqlSessionFactory.openSession().update(getStatement(mapperClass,"updateAll"),entity);
83     }
84
85     /**删除*/
86     @Override
9338de 87     public <T extends Serializable> int deleteWhere(Class<?> mapperClass,SqlSentence sqlSentence) {
C 88         return sqlSessionFactory.openSession().delete(getStatement(mapperClass,"deleteWhere"),sqlSentence);
3fde78 89     }
C 90
91     /**删除*/
92     @Override
93     public <T extends Serializable> int deleteById(Class<?> mapperClass,Object object) {
94         return sqlSessionFactory.openSession().delete(getStatement(mapperClass,"deleteById"),object);
95     }
96
97 }