ChenJiaHe
2021-05-21 76b630351b2db4b3dbc5c427f5d8edb5d488872c
提交 | 用户 | 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
8bc3c9 31     /**获取条数
C 32      * @return*/
3fde78 33     @Override
8bc3c9 34     public <T extends Serializable> int selectCount(Class<?> mapperClass, SqlSentence sqlSentence) {
9338de 35         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCount"),sqlSentence);
3fde78 36     }
C 37
8bc3c9 38     /**获取条数
C 39      * @return*/
40     @Override
41     public <T extends Serializable> int selectCountSql(Class<?> mapperClass, SqlSentence sqlSentence) {
42         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCountSql"),sqlSentence);
43     }
44
3fde78 45     /**获取列表*/
C 46     @Override
47     public <T extends Serializable> List<T> selectList(Class<?> mapperClass, SqlSentence sqlSentence) {
48         return sqlSessionFactory.openSession().selectList(getStatement(mapperClass,"selectList"),sqlSentence);
49     }
50
51     /**获取列表*/
52     @Override
53     public <T extends Serializable> List<Map<String, Object>> selectListMap(Class<?> mapperClass, SqlSentence sqlSentence) {
54         return sqlSessionFactory.openSession().selectList(getStatement(mapperClass,"selectListMap"),sqlSentence);
55     }
56
57     /**获取单条数据*/
58     @Override
59     public <T extends Serializable> T selectOne(Class<?> mapperClass, SqlSentence sqlSentence) {
60         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOne"),sqlSentence);
61     }
62
63     /**获取单条数据*/
64     @Override
65     public <T extends Serializable> Map<String, Object> selectOneMap(Class<?> mapperClass, SqlSentence sqlSentence) {
66         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneMap"),sqlSentence);
67     }
68
69     /**获取单条数据-不含longText的数据*/
70     @Override
71     public <T extends Serializable> T selectOneByKey(Class<?> mapperClass,Object object) {
72         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneByKey"),object);
73     }
74
75     /**获取单条数据-含longText的数据*/
76     @Override
77     public <T extends Serializable> T selectOneByKeyBlob(Class<?> mapperClass,Object object) {
78         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneByKeyBlob"),object);
79     }
80
81     /**更新*/
82     @Override
9338de 83     public <T extends Serializable> int updateWhere(Class<?> mapperClass,SqlSentence sqlSentence) {
C 84         return sqlSessionFactory.openSession().update(getStatement(mapperClass,"updateWhere"),sqlSentence);
3fde78 85     }
C 86
87     /**全部字段更新*/
88     @Override
89     public <T extends Serializable> int updateAll(Class<?> mapperClass,T entity) {
90         return sqlSessionFactory.openSession().update(getStatement(mapperClass,"updateAll"),entity);
91     }
92
93     /**删除*/
94     @Override
9338de 95     public <T extends Serializable> int deleteWhere(Class<?> mapperClass,SqlSentence sqlSentence) {
C 96         return sqlSessionFactory.openSession().delete(getStatement(mapperClass,"deleteWhere"),sqlSentence);
3fde78 97     }
C 98
99     /**删除*/
100     @Override
101     public <T extends Serializable> int deleteById(Class<?> mapperClass,Object object) {
102         return sqlSessionFactory.openSession().delete(getStatement(mapperClass,"deleteById"),object);
103     }
104
105 }