【修改】pom的项目名更改
This commit is contained in:
+300
-300
@@ -1,300 +1,300 @@
|
|||||||
package org.jeecg.common.util.dynamic.db;
|
//package org.jeecg.common.util.dynamic.db;
|
||||||
|
//
|
||||||
import com.alibaba.druid.pool.DruidDataSource;
|
//import com.alibaba.druid.pool.DruidDataSource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
//import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.jeecg.common.exception.JeecgBootException;
|
//import org.jeecg.common.exception.JeecgBootException;
|
||||||
import org.jeecg.common.exception.JeecgBootException;
|
//import org.jeecg.common.exception.JeecgBootException;
|
||||||
import org.jeecg.common.system.vo.DynamicDataSourceModel;
|
//import org.jeecg.common.system.vo.DynamicDataSourceModel;
|
||||||
import org.jeecg.common.util.ReflectHelper;
|
//import org.jeecg.common.util.ReflectHelper;
|
||||||
import org.jeecg.common.util.oConvertUtils;
|
//import org.jeecg.common.util.oConvertUtils;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
//import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
//import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
|
//
|
||||||
import javax.sql.DataSource;
|
//import javax.sql.DataSource;
|
||||||
import java.sql.SQLException;
|
//import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
//import java.util.HashMap;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
import java.util.Map;
|
//import java.util.Map;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* Spring JDBC 实时数据库访问
|
// * Spring JDBC 实时数据库访问
|
||||||
*
|
// *
|
||||||
* @author chenguobin
|
// * @author chenguobin
|
||||||
* @version 1.0
|
// * @version 1.0
|
||||||
* @date 2014-09-05
|
// * @date 2014-09-05
|
||||||
*/
|
// */
|
||||||
@Slf4j
|
//@Slf4j
|
||||||
public class DynamicDBUtil {
|
//public class DynamicDBUtil {
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 获取数据源【最底层方法,不要随便调用】
|
// * 获取数据源【最底层方法,不要随便调用】
|
||||||
*
|
// *
|
||||||
* @param dbSource
|
// * @param dbSource
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
private static DruidDataSource getJdbcDataSource(final DynamicDataSourceModel dbSource) {
|
// private static DruidDataSource getJdbcDataSource(final DynamicDataSourceModel dbSource) {
|
||||||
DruidDataSource dataSource = new DruidDataSource();
|
// DruidDataSource dataSource = new DruidDataSource();
|
||||||
|
//
|
||||||
String driverClassName = dbSource.getDbDriver();
|
// String driverClassName = dbSource.getDbDriver();
|
||||||
String url = dbSource.getDbUrl();
|
// String url = dbSource.getDbUrl();
|
||||||
String dbUser = dbSource.getDbUsername();
|
// String dbUser = dbSource.getDbUsername();
|
||||||
String dbPassword = dbSource.getDbPassword();
|
// String dbPassword = dbSource.getDbPassword();
|
||||||
dataSource.setDriverClassName(driverClassName);
|
// dataSource.setDriverClassName(driverClassName);
|
||||||
dataSource.setUrl(url);
|
// dataSource.setUrl(url);
|
||||||
//dataSource.setValidationQuery("SELECT 1 FROM DUAL");
|
// //dataSource.setValidationQuery("SELECT 1 FROM DUAL");
|
||||||
dataSource.setTestWhileIdle(true);
|
// dataSource.setTestWhileIdle(true);
|
||||||
dataSource.setTestOnBorrow(false);
|
// dataSource.setTestOnBorrow(false);
|
||||||
dataSource.setTestOnReturn(false);
|
// dataSource.setTestOnReturn(false);
|
||||||
dataSource.setBreakAfterAcquireFailure(true);
|
// dataSource.setBreakAfterAcquireFailure(true);
|
||||||
dataSource.setConnectionErrorRetryAttempts(0);
|
// dataSource.setConnectionErrorRetryAttempts(0);
|
||||||
dataSource.setUsername(dbUser);
|
// dataSource.setUsername(dbUser);
|
||||||
dataSource.setMaxWait(60000);
|
// dataSource.setMaxWait(60000);
|
||||||
dataSource.setPassword(dbPassword);
|
// dataSource.setPassword(dbPassword);
|
||||||
|
//
|
||||||
log.info("******************************************");
|
// log.info("******************************************");
|
||||||
log.info("* *");
|
// log.info("* *");
|
||||||
log.info("*====【"+dbSource.getCode()+"】=====Druid连接池已启用 ====*");
|
// log.info("*====【"+dbSource.getCode()+"】=====Druid连接池已启用 ====*");
|
||||||
log.info("* *");
|
// log.info("* *");
|
||||||
log.info("******************************************");
|
// log.info("******************************************");
|
||||||
return dataSource;
|
// return dataSource;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 通过 dbKey ,获取数据源
|
// * 通过 dbKey ,获取数据源
|
||||||
*
|
// *
|
||||||
* @param dbKey
|
// * @param dbKey
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
public static DruidDataSource getDbSourceByDbKey(final String dbKey) {
|
// public static DruidDataSource getDbSourceByDbKey(final String dbKey) {
|
||||||
//获取多数据源配置
|
// //获取多数据源配置
|
||||||
DynamicDataSourceModel dbSource = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey);
|
// DynamicDataSourceModel dbSource = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey);
|
||||||
//先判断缓存中是否存在数据库链接
|
// //先判断缓存中是否存在数据库链接
|
||||||
DruidDataSource cacheDbSource = DataSourceCachePool.getCacheBasicDataSource(dbKey);
|
// DruidDataSource cacheDbSource = DataSourceCachePool.getCacheBasicDataSource(dbKey);
|
||||||
if (cacheDbSource != null && !cacheDbSource.isClosed()) {
|
// if (cacheDbSource != null && !cacheDbSource.isClosed()) {
|
||||||
log.debug("--------getDbSourceBydbKey------------------从缓存中获取DB连接-------------------");
|
// log.debug("--------getDbSourceBydbKey------------------从缓存中获取DB连接-------------------");
|
||||||
return cacheDbSource;
|
// return cacheDbSource;
|
||||||
} else {
|
// } else {
|
||||||
DruidDataSource dataSource = getJdbcDataSource(dbSource);
|
// DruidDataSource dataSource = getJdbcDataSource(dbSource);
|
||||||
if(dataSource!=null && dataSource.isEnable()){
|
// if(dataSource!=null && dataSource.isEnable()){
|
||||||
DataSourceCachePool.putCacheBasicDataSource(dbKey, dataSource);
|
// DataSourceCachePool.putCacheBasicDataSource(dbKey, dataSource);
|
||||||
}else{
|
// }else{
|
||||||
throw new JeecgBootException("动态数据源连接失败,dbKey:"+dbKey);
|
// throw new JeecgBootException("动态数据源连接失败,dbKey:"+dbKey);
|
||||||
}
|
// }
|
||||||
log.info("--------getDbSourceBydbKey------------------创建DB数据库连接-------------------");
|
// log.info("--------getDbSourceBydbKey------------------创建DB数据库连接-------------------");
|
||||||
return dataSource;
|
// return dataSource;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 关闭数据库连接池
|
// * 关闭数据库连接池
|
||||||
*
|
// *
|
||||||
* @param dbKey
|
// * @param dbKey
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
public static void closeDbKey(final String dbKey) {
|
// public static void closeDbKey(final String dbKey) {
|
||||||
DruidDataSource dataSource = getDbSourceByDbKey(dbKey);
|
// DruidDataSource dataSource = getDbSourceByDbKey(dbKey);
|
||||||
try {
|
// try {
|
||||||
if (dataSource != null && !dataSource.isClosed()) {
|
// if (dataSource != null && !dataSource.isClosed()) {
|
||||||
dataSource.getConnection().commit();
|
// dataSource.getConnection().commit();
|
||||||
dataSource.getConnection().close();
|
// dataSource.getConnection().close();
|
||||||
dataSource.close();
|
// dataSource.close();
|
||||||
}
|
// }
|
||||||
} catch (SQLException e) {
|
// } catch (SQLException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
private static JdbcTemplate getJdbcTemplate(String dbKey) {
|
// private static JdbcTemplate getJdbcTemplate(String dbKey) {
|
||||||
DruidDataSource dataSource = getDbSourceByDbKey(dbKey);
|
// DruidDataSource dataSource = getDbSourceByDbKey(dbKey);
|
||||||
return new JdbcTemplate(dataSource);
|
// return new JdbcTemplate(dataSource);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Executes the SQL statement in this <code>PreparedStatement</code> object,
|
// * Executes the SQL statement in this <code>PreparedStatement</code> object,
|
||||||
* which must be an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>, <code>UPDATE</code> or
|
// * which must be an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>, <code>UPDATE</code> or
|
||||||
* <code>DELETE</code>; or an SQL statement that returns nothing,
|
// * <code>DELETE</code>; or an SQL statement that returns nothing,
|
||||||
* such as a DDL statement.
|
// * such as a DDL statement.
|
||||||
*/
|
// */
|
||||||
public static int update(final String dbKey, String sql, Object... param) {
|
// public static int update(final String dbKey, String sql, Object... param) {
|
||||||
int effectCount;
|
// int effectCount;
|
||||||
JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);
|
// JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);
|
||||||
if (ArrayUtils.isEmpty(param)) {
|
// if (ArrayUtils.isEmpty(param)) {
|
||||||
effectCount = jdbcTemplate.update(sql);
|
// effectCount = jdbcTemplate.update(sql);
|
||||||
} else {
|
// } else {
|
||||||
effectCount = jdbcTemplate.update(sql, param);
|
// effectCount = jdbcTemplate.update(sql, param);
|
||||||
}
|
// }
|
||||||
return effectCount;
|
// return effectCount;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 支持miniDao语法操作的Update
|
// * 支持miniDao语法操作的Update
|
||||||
*
|
// *
|
||||||
* @param dbKey 数据源标识
|
// * @param dbKey 数据源标识
|
||||||
* @param sql 执行sql语句,sql支持minidao语法逻辑
|
// * @param sql 执行sql语句,sql支持minidao语法逻辑
|
||||||
* @param data sql语法中需要判断的数据及sql拼接注入中需要的数据
|
// * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
public static int updateByHash(final String dbKey, String sql, HashMap<String, Object> data) {
|
// public static int updateByHash(final String dbKey, String sql, HashMap<String, Object> data) {
|
||||||
int effectCount;
|
// int effectCount;
|
||||||
JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);
|
// JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);
|
||||||
//根据模板获取sql
|
// //根据模板获取sql
|
||||||
sql = FreemarkerParseFactory.parseTemplateContent(sql, data);
|
// sql = FreemarkerParseFactory.parseTemplateContent(sql, data);
|
||||||
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource());
|
// NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource());
|
||||||
effectCount = namedParameterJdbcTemplate.update(sql, data);
|
// effectCount = namedParameterJdbcTemplate.update(sql, data);
|
||||||
return effectCount;
|
// return effectCount;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public static Object findOne(final String dbKey, String sql, Object... param) {
|
// public static Object findOne(final String dbKey, String sql, Object... param) {
|
||||||
List<Map<String, Object>> list;
|
// List<Map<String, Object>> list;
|
||||||
list = findList(dbKey, sql, param);
|
// list = findList(dbKey, sql, param);
|
||||||
if (oConvertUtils.listIsEmpty(list)) {
|
// if (oConvertUtils.listIsEmpty(list)) {
|
||||||
log.error("Except one, but not find actually");
|
// log.error("Except one, but not find actually");
|
||||||
}
|
// }
|
||||||
if (list.size() > 1) {
|
// if (list.size() > 1) {
|
||||||
log.error("Except one, but more than one actually");
|
// log.error("Except one, but more than one actually");
|
||||||
}
|
// }
|
||||||
return list.get(0);
|
// return list.get(0);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 支持miniDao语法操作的查询 返回HashMap
|
// * 支持miniDao语法操作的查询 返回HashMap
|
||||||
*
|
// *
|
||||||
* @param dbKey 数据源标识
|
// * @param dbKey 数据源标识
|
||||||
* @param sql 执行sql语句,sql支持minidao语法逻辑
|
// * @param sql 执行sql语句,sql支持minidao语法逻辑
|
||||||
* @param data sql语法中需要判断的数据及sql拼接注入中需要的数据
|
// * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
public static Object findOneByHash(final String dbKey, String sql, HashMap<String, Object> data) {
|
// public static Object findOneByHash(final String dbKey, String sql, HashMap<String, Object> data) {
|
||||||
List<Map<String, Object>> list;
|
// List<Map<String, Object>> list;
|
||||||
list = findListByHash(dbKey, sql, data);
|
// list = findListByHash(dbKey, sql, data);
|
||||||
if (oConvertUtils.listIsEmpty(list)) {
|
// if (oConvertUtils.listIsEmpty(list)) {
|
||||||
log.error("Except one, but not find actually");
|
// log.error("Except one, but not find actually");
|
||||||
}
|
// }
|
||||||
if (list.size() > 1) {
|
// if (list.size() > 1) {
|
||||||
log.error("Except one, but more than one actually");
|
// log.error("Except one, but more than one actually");
|
||||||
}
|
// }
|
||||||
return list.get(0);
|
// return list.get(0);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 直接sql查询 根据clazz返回单个实例
|
// * 直接sql查询 根据clazz返回单个实例
|
||||||
*
|
// *
|
||||||
* @param dbKey 数据源标识
|
// * @param dbKey 数据源标识
|
||||||
* @param sql 执行sql语句
|
// * @param sql 执行sql语句
|
||||||
* @param clazz 返回实例的Class
|
// * @param clazz 返回实例的Class
|
||||||
* @param param
|
// * @param param
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
@SuppressWarnings("unchecked")
|
// @SuppressWarnings("unchecked")
|
||||||
public static <T> Object findOne(final String dbKey, String sql, Class<T> clazz, Object... param) {
|
// public static <T> Object findOne(final String dbKey, String sql, Class<T> clazz, Object... param) {
|
||||||
Map<String, Object> map = (Map<String, Object>) findOne(dbKey, sql, param);
|
// Map<String, Object> map = (Map<String, Object>) findOne(dbKey, sql, param);
|
||||||
return ReflectHelper.setAll(clazz, map);
|
// return ReflectHelper.setAll(clazz, map);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 支持miniDao语法操作的查询 返回单个实例
|
// * 支持miniDao语法操作的查询 返回单个实例
|
||||||
*
|
// *
|
||||||
* @param dbKey 数据源标识
|
// * @param dbKey 数据源标识
|
||||||
* @param sql 执行sql语句,sql支持minidao语法逻辑
|
// * @param sql 执行sql语句,sql支持minidao语法逻辑
|
||||||
* @param clazz 返回实例的Class
|
// * @param clazz 返回实例的Class
|
||||||
* @param data sql语法中需要判断的数据及sql拼接注入中需要的数据
|
// * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
@SuppressWarnings("unchecked")
|
// @SuppressWarnings("unchecked")
|
||||||
public static <T> Object findOneByHash(final String dbKey, String sql, Class<T> clazz, HashMap<String, Object> data) {
|
// public static <T> Object findOneByHash(final String dbKey, String sql, Class<T> clazz, HashMap<String, Object> data) {
|
||||||
Map<String, Object> map = (Map<String, Object>) findOneByHash(dbKey, sql, data);
|
// Map<String, Object> map = (Map<String, Object>) findOneByHash(dbKey, sql, data);
|
||||||
return ReflectHelper.setAll(clazz, map);
|
// return ReflectHelper.setAll(clazz, map);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public static List<Map<String, Object>> findList(final String dbKey, String sql, Object... param) {
|
// public static List<Map<String, Object>> findList(final String dbKey, String sql, Object... param) {
|
||||||
List<Map<String, Object>> list;
|
// List<Map<String, Object>> list;
|
||||||
JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);
|
// JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);
|
||||||
|
//
|
||||||
if (ArrayUtils.isEmpty(param)) {
|
// if (ArrayUtils.isEmpty(param)) {
|
||||||
list = jdbcTemplate.queryForList(sql);
|
// list = jdbcTemplate.queryForList(sql);
|
||||||
} else {
|
// } else {
|
||||||
list = jdbcTemplate.queryForList(sql, param);
|
// list = jdbcTemplate.queryForList(sql, param);
|
||||||
}
|
// }
|
||||||
return list;
|
// return list;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 支持miniDao语法操作的查询
|
// * 支持miniDao语法操作的查询
|
||||||
*
|
// *
|
||||||
* @param dbKey 数据源标识
|
// * @param dbKey 数据源标识
|
||||||
* @param sql 执行sql语句,sql支持minidao语法逻辑
|
// * @param sql 执行sql语句,sql支持minidao语法逻辑
|
||||||
* @param data sql语法中需要判断的数据及sql拼接注入中需要的数据
|
// * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
public static List<Map<String, Object>> findListByHash(final String dbKey, String sql, HashMap<String, Object> data) {
|
// public static List<Map<String, Object>> findListByHash(final String dbKey, String sql, HashMap<String, Object> data) {
|
||||||
List<Map<String, Object>> list;
|
// List<Map<String, Object>> list;
|
||||||
JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);
|
// JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);
|
||||||
//根据模板获取sql
|
// //根据模板获取sql
|
||||||
sql = FreemarkerParseFactory.parseTemplateContent(sql, data);
|
// sql = FreemarkerParseFactory.parseTemplateContent(sql, data);
|
||||||
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource());
|
// NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource());
|
||||||
list = namedParameterJdbcTemplate.queryForList(sql, data);
|
// list = namedParameterJdbcTemplate.queryForList(sql, data);
|
||||||
return list;
|
// return list;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//此方法只能返回单列,不能返回实体类
|
// //此方法只能返回单列,不能返回实体类
|
||||||
public static <T> List<T> findList(final String dbKey, String sql, Class<T> clazz, Object... param) {
|
// public static <T> List<T> findList(final String dbKey, String sql, Class<T> clazz, Object... param) {
|
||||||
List<T> list;
|
// List<T> list;
|
||||||
JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);
|
// JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);
|
||||||
|
//
|
||||||
if (ArrayUtils.isEmpty(param)) {
|
// if (ArrayUtils.isEmpty(param)) {
|
||||||
list = jdbcTemplate.queryForList(sql, clazz);
|
// list = jdbcTemplate.queryForList(sql, clazz);
|
||||||
} else {
|
// } else {
|
||||||
list = jdbcTemplate.queryForList(sql, clazz, param);
|
// list = jdbcTemplate.queryForList(sql, clazz, param);
|
||||||
}
|
// }
|
||||||
return list;
|
// return list;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 支持miniDao语法操作的查询 返回单列数据list
|
// * 支持miniDao语法操作的查询 返回单列数据list
|
||||||
*
|
// *
|
||||||
* @param dbKey 数据源标识
|
// * @param dbKey 数据源标识
|
||||||
* @param sql 执行sql语句,sql支持minidao语法逻辑
|
// * @param sql 执行sql语句,sql支持minidao语法逻辑
|
||||||
* @param clazz 类型Long、String等
|
// * @param clazz 类型Long、String等
|
||||||
* @param data sql语法中需要判断的数据及sql拼接注入中需要的数据
|
// * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
public static <T> List<T> findListByHash(final String dbKey, String sql, Class<T> clazz, HashMap<String, Object> data) {
|
// public static <T> List<T> findListByHash(final String dbKey, String sql, Class<T> clazz, HashMap<String, Object> data) {
|
||||||
List<T> list;
|
// List<T> list;
|
||||||
JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);
|
// JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey);
|
||||||
//根据模板获取sql
|
// //根据模板获取sql
|
||||||
sql = FreemarkerParseFactory.parseTemplateContent(sql, data);
|
// sql = FreemarkerParseFactory.parseTemplateContent(sql, data);
|
||||||
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource());
|
// NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource());
|
||||||
list = namedParameterJdbcTemplate.queryForList(sql, data, clazz);
|
// list = namedParameterJdbcTemplate.queryForList(sql, data, clazz);
|
||||||
return list;
|
// return list;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 直接sql查询 返回实体类列表
|
// * 直接sql查询 返回实体类列表
|
||||||
*
|
// *
|
||||||
* @param dbKey 数据源标识
|
// * @param dbKey 数据源标识
|
||||||
* @param sql 执行sql语句,sql支持 minidao 语法逻辑
|
// * @param sql 执行sql语句,sql支持 minidao 语法逻辑
|
||||||
* @param clazz 返回实体类列表的class
|
// * @param clazz 返回实体类列表的class
|
||||||
* @param param sql拼接注入中需要的数据
|
// * @param param sql拼接注入中需要的数据
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
public static <T> List<T> findListEntities(final String dbKey, String sql, Class<T> clazz, Object... param) {
|
// public static <T> List<T> findListEntities(final String dbKey, String sql, Class<T> clazz, Object... param) {
|
||||||
List<Map<String, Object>> queryList = findList(dbKey, sql, param);
|
// List<Map<String, Object>> queryList = findList(dbKey, sql, param);
|
||||||
return ReflectHelper.transList2Entrys(queryList, clazz);
|
// return ReflectHelper.transList2Entrys(queryList, clazz);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 支持miniDao语法操作的查询 返回实体类列表
|
// * 支持miniDao语法操作的查询 返回实体类列表
|
||||||
*
|
// *
|
||||||
* @param dbKey 数据源标识
|
// * @param dbKey 数据源标识
|
||||||
* @param sql 执行sql语句,sql支持minidao语法逻辑
|
// * @param sql 执行sql语句,sql支持minidao语法逻辑
|
||||||
* @param clazz 返回实体类列表的class
|
// * @param clazz 返回实体类列表的class
|
||||||
* @param data sql语法中需要判断的数据及sql拼接注入中需要的数据
|
// * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
public static <T> List<T> findListEntitiesByHash(final String dbKey, String sql, Class<T> clazz, HashMap<String, Object> data) {
|
// public static <T> List<T> findListEntitiesByHash(final String dbKey, String sql, Class<T> clazz, HashMap<String, Object> data) {
|
||||||
List<Map<String, Object>> queryList = findListByHash(dbKey, sql, data);
|
// List<Map<String, Object>> queryList = findListByHash(dbKey, sql, data);
|
||||||
return ReflectHelper.transList2Entrys(queryList, clazz);
|
// return ReflectHelper.transList2Entrys(queryList, clazz);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@@ -13,12 +13,12 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
<groupId>com.jero.boot</groupId>
|
||||||
<artifactId>jeecg-boot-base-core</artifactId>
|
<artifactId>jeecg-boot-base-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- 引入微服务启动依赖 starter
|
<!-- 引入微服务启动依赖 starter
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
<groupId>com.jero.boot</groupId>
|
||||||
<artifactId>jeecg-boot-starter-cloud</artifactId>
|
<artifactId>jeecg-boot-starter-cloud</artifactId>
|
||||||
</dependency> -->
|
</dependency> -->
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
<groupId>com.jero.boot</groupId>
|
||||||
<artifactId>jeecg-system-cloud-api</artifactId>
|
<artifactId>jeecg-system-cloud-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Nacos注册中心 -->
|
<!-- Nacos注册中心 -->
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<!--jeecg-tools-->
|
<!--jeecg-tools-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
<groupId>com.jero.boot</groupId>
|
||||||
<artifactId>jeecg-boot-base-tools</artifactId>
|
<artifactId>jeecg-boot-base-tools</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--加载配置信息-->
|
<!--加载配置信息-->
|
||||||
|
|||||||
@@ -13,18 +13,18 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- jeecg 微服务基础依赖-->
|
<!-- jeecg 微服务基础依赖-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
<groupId>com.jero.boot</groupId>
|
||||||
<artifactId>jeecg-boot-starter-cloud</artifactId>
|
<artifactId>jeecg-boot-starter-cloud</artifactId>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
<groupId>com.jero.boot</groupId>
|
||||||
<artifactId>jeecg-system-cloud-api</artifactId>
|
<artifactId>jeecg-system-cloud-api</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--redis-->
|
<!--redis-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
<groupId>com.jero.boot</groupId>
|
||||||
<artifactId>jeecg-boot-starter-redis</artifactId>
|
<artifactId>jeecg-boot-starter-redis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- spring-cloud网关-->
|
<!-- spring-cloud网关-->
|
||||||
|
|||||||
@@ -14,35 +14,35 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- 引入jeecg-boot-starter-cloud依赖 -->
|
<!-- 引入jeecg-boot-starter-cloud依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
<groupId>com.jero.boot</groupId>
|
||||||
<artifactId>jeecg-boot-starter-cloud</artifactId>
|
<artifactId>jeecg-boot-starter-cloud</artifactId>
|
||||||
<!--system模块需要排除jeecg-system-cloud-api-->
|
<!--system模块需要排除jeecg-system-cloud-api-->
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
<groupId>com.jero.boot</groupId>
|
||||||
<artifactId>jeecg-system-cloud-api</artifactId>
|
<artifactId>jeecg-system-cloud-api</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- 引入jeecg-boot-module-system依赖 -->
|
<!-- 引入jeecg-boot-module-system依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
<groupId>com.jero.boot</groupId>
|
||||||
<artifactId>jeecg-boot-module-system</artifactId>
|
<artifactId>jeecg-boot-module-system</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--rabbitmq消息队列-->
|
<!--rabbitmq消息队列-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
<groupId>com.jero.boot</groupId>
|
||||||
<artifactId>jeecg-boot-starter-rabbitmq</artifactId>
|
<artifactId>jeecg-boot-starter-rabbitmq</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--xxl-job定时任务-->
|
<!--xxl-job定时任务-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
<groupId>com.jero.boot</groupId>
|
||||||
<artifactId>jeecg-boot-starter-job</artifactId>
|
<artifactId>jeecg-boot-starter-job</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- 分布式锁依赖 -->
|
<!-- 分布式锁依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
<groupId>com.jero.boot</groupId>
|
||||||
<artifactId>jeecg-boot-starter-lock</artifactId>
|
<artifactId>jeecg-boot-starter-lock</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,4 @@
|
|||||||
<module>jeecg-cloud-xxljob</module>
|
<module>jeecg-cloud-xxljob</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
+2
-2
@@ -52,10 +52,10 @@
|
|||||||
<module>jeecg-boot-module-demo</module>
|
<module>jeecg-boot-module-demo</module>
|
||||||
<module>jeecg-boot-module-system</module>
|
<module>jeecg-boot-module-system</module>
|
||||||
|
|
||||||
<!-- 需要微服务,请打开注释
|
<!-- <!– 需要微服务,请打开注释-->
|
||||||
<module>jeecg-boot-starter</module>
|
<module>jeecg-boot-starter</module>
|
||||||
<module>jeecg-cloud-module</module>
|
<module>jeecg-cloud-module</module>
|
||||||
-->
|
<!-- –>-->
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
|
|||||||
Reference in New Issue
Block a user