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