chenjiahe
2023-02-07 1b181507f2564bfd327cc3a8e5d75a8620c3d09d
提交 | 用户 | age
3fde78 1 package com.hx.common.service.impl;
C 2
3 import com.hx.common.dao.CommonDao;
a48817 4 import com.hx.common.dao.mapper.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
bcc2fa 32     @Override
C 33     public <T extends Serializable> int insertById(Class<?> mapperClass, T entity) {
34         return sqlSessionFactory.openSession().insert(getStatement(mapperClass,"insertById"),entity);
35     }
36
8bc3c9 37     /**获取条数
C 38      * @return*/
3fde78 39     @Override
8bc3c9 40     public <T extends Serializable> int selectCount(Class<?> mapperClass, SqlSentence sqlSentence) {
9338de 41         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCount"),sqlSentence);
3fde78 42     }
C 43
8bc3c9 44     /**获取条数
C 45      * @return*/
46     @Override
47     public <T extends Serializable> int selectCountSql(Class<?> mapperClass, SqlSentence sqlSentence) {
48         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCountSql"),sqlSentence);
49     }
50
3fde78 51     /**获取列表*/
C 52     @Override
53     public <T extends Serializable> List<T> selectList(Class<?> mapperClass, SqlSentence sqlSentence) {
54         return sqlSessionFactory.openSession().selectList(getStatement(mapperClass,"selectList"),sqlSentence);
55     }
56
57     /**获取列表*/
58     @Override
59     public <T extends Serializable> List<Map<String, Object>> selectListMap(Class<?> mapperClass, SqlSentence sqlSentence) {
60         return sqlSessionFactory.openSession().selectList(getStatement(mapperClass,"selectListMap"),sqlSentence);
61     }
62
63     /**获取单条数据*/
64     @Override
65     public <T extends Serializable> T selectOne(Class<?> mapperClass, SqlSentence sqlSentence) {
66         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOne"),sqlSentence);
67     }
68
69     /**获取单条数据*/
70     @Override
71     public <T extends Serializable> Map<String, Object> selectOneMap(Class<?> mapperClass, SqlSentence sqlSentence) {
72         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneMap"),sqlSentence);
73     }
74
75     /**获取单条数据-不含longText的数据*/
76     @Override
77     public <T extends Serializable> T selectOneByKey(Class<?> mapperClass,Object object) {
78         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneByKey"),object);
79     }
80
81     /**获取单条数据-含longText的数据*/
82     @Override
83     public <T extends Serializable> T selectOneByKeyBlob(Class<?> mapperClass,Object object) {
84         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneByKeyBlob"),object);
85     }
86
87     /**更新*/
88     @Override
9338de 89     public <T extends Serializable> int updateWhere(Class<?> mapperClass,SqlSentence sqlSentence) {
C 90         return sqlSessionFactory.openSession().update(getStatement(mapperClass,"updateWhere"),sqlSentence);
3fde78 91     }
C 92
93     /**全部字段更新*/
94     @Override
95     public <T extends Serializable> int updateAll(Class<?> mapperClass,T entity) {
96         return sqlSessionFactory.openSession().update(getStatement(mapperClass,"updateAll"),entity);
97     }
98
99     /**删除*/
100     @Override
9338de 101     public <T extends Serializable> int deleteWhere(Class<?> mapperClass,SqlSentence sqlSentence) {
C 102         return sqlSessionFactory.openSession().delete(getStatement(mapperClass,"deleteWhere"),sqlSentence);
3fde78 103     }
C 104
105     /**删除*/
106     @Override
107     public <T extends Serializable> int deleteById(Class<?> mapperClass,Object object) {
108         return sqlSessionFactory.openSession().delete(getStatement(mapperClass,"deleteById"),object);
109     }
110
93b505 111     /**更新sql语句(全语句)*/
C 112     @Override
113     public <T extends Serializable> int updateSentence(SqlSentence sqlSentence) {
0344dc 114         return sqlSessionFactory.openSession().update(getStatement(CommonMapper.class,"updateSentence"),sqlSentence);
93b505 115     }
C 116
b1097d 117     /**查询条数(全语句)*/
C 118     @Override
119     public <T extends Serializable> int selectCountSql(SqlSentence sqlSentence) {
0344dc 120         return sqlSessionFactory.openSession().selectOne(getStatement(CommonMapper.class,"selectCountSql"),sqlSentence);
b1097d 121     }
93b505 122
3fde78 123 }