|
@@ -25,6 +25,7 @@ import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.context.ApplicationContextAware;
|
|
|
import org.springframework.dao.DataAccessException;
|
|
|
import org.springframework.dao.EmptyResultDataAccessException;
|
|
|
+import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
|
|
import org.springframework.jdbc.core.*;
|
|
|
import org.springframework.jdbc.core.namedparam.*;
|
|
|
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
|
@@ -399,12 +400,31 @@ public class BasicBaseDao implements ApplicationContextAware,
|
|
|
public <T> T executeQueryCount(String sql, Object o, ListDynamicSearch search, Class<T> elementType) throws Exception {
|
|
|
JdbcParamsModel jdbcParamsModel = commonParseSql(sql, o, search);
|
|
|
long start = System.currentTimeMillis();
|
|
|
- T ts = this.jdbcTemplate.queryForObject(jdbcParamsModel.getSql(), jdbcParamsModel.getObjects(), elementType);
|
|
|
+ T ts = executorQuerySingleObject(elementType, jdbcParamsModel);
|
|
|
long time = System.currentTimeMillis() - start;
|
|
|
logger.debug(" SQL 执行耗时 : " + time);
|
|
|
return ts;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询单个对象,避免查询不到框架底层直接异常
|
|
|
+ *
|
|
|
+ * @param elementType
|
|
|
+ * @param jdbcParamsModel
|
|
|
+ * @param <T>
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private <T> T executorQuerySingleObject(Class<T> elementType, JdbcParamsModel jdbcParamsModel) {
|
|
|
+ try {
|
|
|
+ return this.jdbcTemplate.queryForObject(jdbcParamsModel.getSql(), jdbcParamsModel.getObjects(), elementType);
|
|
|
+ } catch (EmptyResultDataAccessException e) {
|
|
|
+ return null;
|
|
|
+ } catch (IncorrectResultSizeDataAccessException e) {
|
|
|
+ logger.error("数据异常,只要查询一个,但是结果集是多个!", e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 查询一个数据集合对象,根据自定义的数据转换器返回
|