|
@@ -0,0 +1,388 @@
|
|
|
+package com.bzd.common.config.dao;
|
|
|
+
|
|
|
+
|
|
|
+import org.apache.ibatis.session.SqlSession;
|
|
|
+import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
+import org.mybatis.spring.SqlSessionTemplate;
|
|
|
+import org.springframework.stereotype.Repository;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * dao底层操作处理工具类
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @版本 v1.0
|
|
|
+*/
|
|
|
+@Repository
|
|
|
+public class DaoBase {
|
|
|
+
|
|
|
+
|
|
|
+ @Resource(name="sqlSessionTemplate")
|
|
|
+ private SqlSessionTemplate sqlSessionTemplate;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通用的更新;删除;插入添加
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 int
|
|
|
+ */
|
|
|
+ public int execute(final String sqlMapId) throws Exception {
|
|
|
+ return sqlSessionTemplate.update(sqlMapId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通用的更新;删除;插入添加
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 int
|
|
|
+ */
|
|
|
+ public int execute(final String sqlMapId,final Object objParam) throws Exception{
|
|
|
+ return sqlSessionTemplate.update(sqlMapId,objParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**批量插入|更新|删除*/
|
|
|
+ public int executeBatch(final String sqlMapId) throws Exception {
|
|
|
+ return sqlSessionTemplate.update(sqlMapId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**批量插入|更新|删除,objParam可以是List<HashMap<String, Object>>*/
|
|
|
+ public int executeBatch(final String sqlMapId, final Object objParam) throws Exception {
|
|
|
+ return sqlSessionTemplate.update(sqlMapId,objParam);
|
|
|
+ }
|
|
|
+ /**批量插入|更新|删除,objParam可以是List<HashMap<String, Object>>*/
|
|
|
+ public int executeBatchNew(final String sqlMapId, final Object objParam) throws Exception {
|
|
|
+ SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory();
|
|
|
+ //批量执行器
|
|
|
+ SqlSession sqlSession = sqlSessionFactory.openSession(false);
|
|
|
+ try{
|
|
|
+ if(objParam!=null){
|
|
|
+ sqlSession.update(sqlMapId, objParam);
|
|
|
+ sqlSession.flushStatements();
|
|
|
+ sqlSession.commit();
|
|
|
+ sqlSession.clearCache();
|
|
|
+ }
|
|
|
+ }finally{
|
|
|
+ sqlSession.close();
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用于查询返回Integer
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 Integer
|
|
|
+ */
|
|
|
+ public Integer queryForInteger(final String sqlMapId) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectOne(sqlMapId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用于查询返回Integer
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 Integer
|
|
|
+ */
|
|
|
+ public Integer queryForInteger(final String sqlMapId, final Object objParam) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectOne(sqlMapId,objParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用于查询返回String
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 String
|
|
|
+ */
|
|
|
+ public String queryForString(final String sqlMapId) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectOne(sqlMapId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用于查询返回String
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 String
|
|
|
+ */
|
|
|
+ public String queryForString(final String sqlMapId, final Object objParam) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectOne(sqlMapId,objParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id去查询,或必须保证sql所查询的结果只有一条或限制返回一条数据
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 Map<String,Object>
|
|
|
+ * @创建时间 2024年09月24日 21:03:07
|
|
|
+ */
|
|
|
+ public Map<String, Object> queryForMap(final String sqlMapId) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectOne(sqlMapId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 必须保存sql所查询的结果只有一条或限制返回一条数据
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 Map<String,Object>
|
|
|
+ * @创建时间 2024年09月24日 21:03:49
|
|
|
+
|
|
|
+ */
|
|
|
+ public Map<String, Object> queryForMap(final String sqlMapId, final Object objParam) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectOne(sqlMapId,objParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id去查询,或必须保证sql所查询的结果只有一条或限制返回一条数据
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 HashMap《String,Object》
|
|
|
+ * @创建时间 2024年09月24日 21:03:07
|
|
|
+
|
|
|
+ */
|
|
|
+ public HashMap<String, Object> queryForHashMap(final String sqlMapId) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectOne(sqlMapId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 必须保存sql所查询的结果只有一条或限制返回一条数据
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 HashMap《String,Object》
|
|
|
+ * @创建时间 2024年09月24日 21:03:49
|
|
|
+
|
|
|
+ */
|
|
|
+ public HashMap<String, Object> queryForHashMap(final String sqlMapId, final Object objParam) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectOne(sqlMapId,objParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 必须保存sql所查询的结果只有一条或限制返回一条数据
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 HashMap《String,Object》
|
|
|
+ * @创建时间 2024年09月24日 21:03:49
|
|
|
+ * @QQ号码 444141300
|
|
|
+ * @主页 http://www.hguo.org
|
|
|
+ */
|
|
|
+ public HashMap<String,String> queryForHashMapString(final String sqlMapId, final Object objParam) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectOne(sqlMapId,objParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询返回List《Map》,含分页
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 List<Map<String,Object>>
|
|
|
+ * @创建时间 2024年09月24日 21:04:14
|
|
|
+
|
|
|
+ */
|
|
|
+ public List<Map<String, Object>> queryForListMap(final String sqlMapId) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectList(sqlMapId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询返回List《Map》,含分页
|
|
|
+ * @param sqlMapId
|
|
|
+ * @param objParam
|
|
|
+ * @throws Exception
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 List<Map<String,Object>>
|
|
|
+ * @创建时间 2016年12月25日 上午12:47:44
|
|
|
+ * @QQ号码 444141300
|
|
|
+ * @官网 http://www.hguo.org
|
|
|
+ */
|
|
|
+ public List<Map<String, Object>> queryForListMap(final String sqlMapId, final Object objParam) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectList(sqlMapId,objParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询返回List《HashMap》,含分页
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 List<Map<String,Object>>
|
|
|
+ * @创建时间 2024年09月24日 21:04:14
|
|
|
+
|
|
|
+ */
|
|
|
+ public List<HashMap<String, Object>> queryForListHashMap(final String sqlMapId) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectList(sqlMapId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 谨慎使用,如果报错则换成返回List<HashMap<String,Object>>
|
|
|
+ * @param
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @QQ 444141300
|
|
|
+ * @创建时间 2018年9月14日 14:01
|
|
|
+ */
|
|
|
+ public List<HashMap<String,String>> queryForListString(final String sqlMapId) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectList(sqlMapId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 谨慎使用,如果报错则换成返回List<HashMap<String,Object>>
|
|
|
+ * @param
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @QQ 444141300
|
|
|
+ * @创建时间 2018年9月14日 14:01
|
|
|
+ */
|
|
|
+ public List<HashMap<String,String>> queryForListString(final String sqlMapId,final Object objParam) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectList(sqlMapId,objParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询返回List《HashMap》,含分页
|
|
|
+ * @param sqlMapId
|
|
|
+ * @param objParam
|
|
|
+ * @throws Exception
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 List<Map<String,Object>>
|
|
|
+ * @创建时间 2016年12月25日 上午12:47:44
|
|
|
+ * @QQ号码 444141300
|
|
|
+ * @官网 http://www.hguo.org
|
|
|
+ */
|
|
|
+ public List<HashMap<String, Object>> queryForListHashMap(final String sqlMapId,final Object objParam) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectList(sqlMapId,objParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询Serializable序列化对象数据对象
|
|
|
+ * @param sqlMapId
|
|
|
+ * @throws Exception
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 PageData
|
|
|
+ * @创建时间 2024年09月24日 下午11:12:57
|
|
|
+ * @QQ号码 444141300
|
|
|
+ * @官网 http://www.hguo.org
|
|
|
+ */
|
|
|
+ public Serializable queryForSerializable(final String sqlMapId) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectOne(sqlMapId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询Serializable序列化对象数据对象
|
|
|
+ * @param sqlMapId
|
|
|
+ * @param objParam
|
|
|
+ * @throws Exception
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 PageData
|
|
|
+ * @创建时间 2016年12月25日 上午12:46:20
|
|
|
+ * @QQ号码 444141300
|
|
|
+ * @官网 http://www.hguo.org
|
|
|
+ */
|
|
|
+ public Serializable queryForSerializable(final String sqlMapId, final Object objParam) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectOne(sqlMapId,objParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询ListSerializable序列化对象数据对象
|
|
|
+ * @param sqlMapId
|
|
|
+ * @throws Exception
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 PageData
|
|
|
+ * @创建时间 2024年09月24日 下午11:12:57
|
|
|
+ * @QQ号码 444141300
|
|
|
+ * @官网 http://www.hguo.org
|
|
|
+ */
|
|
|
+ public List<Serializable> queryForListSerializable(final String sqlMapId) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectList(sqlMapId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询ListSerializable序列化对象数据对象
|
|
|
+ * @param sqlMapId
|
|
|
+ * @param objParam
|
|
|
+ * @throws Exception
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 PageData
|
|
|
+ * @创建时间 2016年12月25日 上午12:46:20
|
|
|
+ * @QQ号码 444141300
|
|
|
+ * @官网 http://www.hguo.org
|
|
|
+ */
|
|
|
+ public List<Serializable> queryForListSerializable(final String sqlMapId, final Object objParam) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectList(sqlMapId,objParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询PageData数据对象
|
|
|
+ * @param sqlMapId
|
|
|
+ * @throws Exception
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 PageData
|
|
|
+ * @创建时间 2024年09月24日 下午11:12:57
|
|
|
+ * @QQ号码 444141300
|
|
|
+ * @官网 http://www.hguo.org
|
|
|
+ */
|
|
|
+ public PageData queryForPageData(final String sqlMapId) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectOne(sqlMapId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询PageData数据对象
|
|
|
+ * @param sqlMapId
|
|
|
+ * @param objParam
|
|
|
+ * @throws Exception
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 PageData
|
|
|
+ * @创建时间 2016年12月25日 上午12:46:20
|
|
|
+ * @QQ号码 444141300
|
|
|
+ * @官网 http://www.hguo.org
|
|
|
+ */
|
|
|
+ public PageData queryForPageData(final String sqlMapId, final Object objParam) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectOne(sqlMapId,objParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询List《PageData》数据对象 ,含分页
|
|
|
+ * @param sqlMapId
|
|
|
+ * @throws Exception
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 List<PageData>
|
|
|
+ * @创建时间 2016年12月25日 上午12:46:48
|
|
|
+ * @QQ号码 444141300
|
|
|
+ * @官网 http://www.hguo.org
|
|
|
+ */
|
|
|
+ public List<PageData> queryForListPageData(final String sqlMapId) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectList(sqlMapId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询List《PageData》数据对象 ,含分页
|
|
|
+ * @param sqlMapId
|
|
|
+ * @param objParam
|
|
|
+ * @throws Exception
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 List<PageData>
|
|
|
+ * @创建时间 2016年12月25日 上午12:46:53
|
|
|
+ * @QQ号码 444141300
|
|
|
+ * @官网 http://www.hguo.org
|
|
|
+ */
|
|
|
+ public List<PageData> queryForListPageData(final String sqlMapId, final Object objParam) throws Exception {
|
|
|
+ return sqlSessionTemplate.selectList(sqlMapId,objParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 带分页查询功能;返回key为total总条数总记录数,key为listData返回的list数据集合
|
|
|
+ * @param sqlMapIdTotal 总条数总记录数的sql映射
|
|
|
+ * @param sqlMapIdData 返回的list数据集合的sql映射
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 HashMap< String,Object >,含total总条数总记录数;listData分页的数据
|
|
|
+ * @创建时间 2024年1月10日 下午5:56:08
|
|
|
+
|
|
|
+ */
|
|
|
+ public HashMap<String,Object> queryForPage(final HashMap<String,Object> params,final String sqlMapIdListData,final String sqlMapIdTotal)throws Exception{
|
|
|
+ final HashMap<String,Object> map = new HashMap<String,Object>(0);
|
|
|
+ final Integer total = sqlSessionTemplate.selectOne(sqlMapIdTotal,params);
|
|
|
+ final List<Object> list = sqlSessionTemplate.selectList(sqlMapIdListData,params);
|
|
|
+ map.put(ConfigFile.total,total);
|
|
|
+ map.put(ConfigFile.listData,list);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 带分页查询功能;返回key为total总条数总记录数,key为listData返回的list数据集合
|
|
|
+ * @param sqlMapIdTotal 总条数总记录数的sql映射
|
|
|
+ * @param sqlMapIdData 返回的list数据集合的sql映射
|
|
|
+ * @作者 LiXiangFei
|
|
|
+ * @返回值类型 HashMap< String,Object >,含total总条数总记录数;listData分页的数据
|
|
|
+ * @创建时间 2024年1月10日 下午5:56:08
|
|
|
+
|
|
|
+ */
|
|
|
+ public HashMap<String,Object> queryForPageData(final PageData params,final String sqlMapIdListData,final String sqlMapIdTotal)throws Exception{
|
|
|
+ final HashMap<String, Object> map = new HashMap<String,Object>(0);
|
|
|
+ final Integer total = sqlSessionTemplate.selectOne(sqlMapIdTotal,params);
|
|
|
+ final List<Object> list = sqlSessionTemplate.selectList(sqlMapIdListData,params);
|
|
|
+ map.put(ConfigFile.total,total);
|
|
|
+ map.put(ConfigFile.listData,list);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+}
|