fhx
2024-09-29 e0ef9fe0ded50ac2c9e40c8616c99007048521c4
提交 | 用户 | age
826b66 1 package com.hx.common.service.impl;
C 2
3 import com.hx.common.dao.CommonDao;
4 import com.hx.common.dao.mapper.CommonMapper;
5 import com.hx.mybatisTool.SqlSentence;
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
32     @Override
33     public <T extends Serializable> int insertById(Class<?> mapperClass, T entity) {
34         return sqlSessionFactory.openSession().insert(getStatement(mapperClass,"insertById"),entity);
35     }
36
37     /**获取条数
38      * @return*/
39     @Override
40     public <T extends Serializable> int selectCount(Class<?> mapperClass, SqlSentence sqlSentence) {
41         return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCount"),sqlSentence);
42     }
43
44     /**获取条数
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
51     /**获取列表*/
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
89     public <T extends Serializable> int updateWhere(Class<?> mapperClass,SqlSentence sqlSentence) {
90         return sqlSessionFactory.openSession().update(getStatement(mapperClass,"updateWhere"),sqlSentence);
91     }
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
101     public <T extends Serializable> int deleteWhere(Class<?> mapperClass,SqlSentence sqlSentence) {
102         return sqlSessionFactory.openSession().delete(getStatement(mapperClass,"deleteWhere"),sqlSentence);
103     }
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
111     /**更新sql语句(全语句)*/
112     @Override
113     public <T extends Serializable> int updateSentence(SqlSentence sqlSentence) {
114         return sqlSessionFactory.openSession().update(getStatement(CommonMapper.class,"updateSentence"),sqlSentence);
115     }
116
117     /**查询条数(全语句)*/
118     @Override
119     public <T extends Serializable> int selectCountSql(SqlSentence sqlSentence) {
120         return sqlSessionFactory.openSession().selectOne(getStatement(CommonMapper.class,"selectCountSql"),sqlSentence);
121     }
122
123 }