diff --git a/README.md b/README.md
index 7e0b5e8..54e32fa 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
MiniDao
=======
-当前最新版本: 1.8.23 (发布日期:20210728)
+当前最新版本: 1.8.3 (发布日期:20210809)
@@ -27,13 +27,29 @@ MiniDao 是一款轻量级JAVA持久层框架,基于 SpringJdbc + freemarker
* SQL标签采用[Freemarker的基本语法](http://blog.csdn.net/zhangdaiscott/article/details/77505453)
+
如何快速集成minidao?
-----------------------------------
#### 方式一:springboot2与minidao集成
-[https://minidao.mydoc.io/?t=336070](https://minidao.mydoc.io/?t=336070)
+```
+
+ org.jeecgframework
+ minidao-pe
+ 1.8.3
+
+```
+[文档](https://minidao.mydoc.io/?t=336070)
#### 方式二:springmvc与minidao集成
-[https://minidao.mydoc.io/?t=293634](https://minidao.mydoc.io/?t=293634)
+```
+
+ org.jeecgframework
+ minidao-spring-boot-starter
+ 1.8.3
+
+```
+
+[文档](https://minidao.mydoc.io/?t=293634)
diff --git a/minidao-pe-example/pom.xml b/minidao-pe-example/pom.xml
index e360780..8c7f0ee 100644
--- a/minidao-pe-example/pom.xml
+++ b/minidao-pe-example/pom.xml
@@ -8,7 +8,7 @@
- 1.8.23
+ 1.8.3
4.13.1
5.2.10.RELEASE
diff --git a/minidao-pe-framework/pom.xml b/minidao-pe-framework/pom.xml
index f8bab4f..b417a8c 100644
--- a/minidao-pe-framework/pom.xml
+++ b/minidao-pe-framework/pom.xml
@@ -4,7 +4,7 @@
org.jeecgframework
minidao-pe
- 1.8.23
+ 1.8.3
jar
minidao-pe
diff --git a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/aop/MiniDaoHandler.java b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/aop/MiniDaoHandler.java
index 041f7b3..9a62431 100644
--- a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/aop/MiniDaoHandler.java
+++ b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/aop/MiniDaoHandler.java
@@ -110,6 +110,10 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
// Step.3解析SQL模板,返回可执行SQL
String executeSql = parseSqlTemplate(method, templateSql, sqlParamsMap);
+ //jeecg : Minidao报错“Template java/lang/Object_toString.sql not found”的解决方案
+ if(executeSql==null || "".equals(executeSql)){
+ return null;
+ }
// Step.4 组装SQL占位符参数
Map sqlMap = installPlaceholderSqlParam(executeSql, sqlParamsMap);
@@ -130,7 +134,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
}
}
if (showSql) {
- logger.info("MiniDao-SQL:\n\n" + executeSql);
+ logger.info("Print MiniDao-Original-SQL :\n\n" + executeSql);
}
return returnObj;
}
@@ -394,18 +398,18 @@ private Object getReturnMinidaoResult(MiniDaoPage pageSetting, Method method, St
if (returnType.isAssignableFrom(MiniDaoPage.class)) {
if (paramMap != null) {
String countsql = countSqlParser.getSmartCountSql(executeSql);
- logger.info("page countsql===>"+countsql);
+ logger.info("page countsql===> "+countsql);
pageSetting.setTotal(namedParameterJdbcTemplate.queryForObject(countsql, paramMap, Integer.class));
} else {
String countsql = countSqlParser.getSmartCountSql(executeSql);
- logger.info("page countsql===>"+countsql);
+ logger.info("page countsql===> "+countsql);
pageSetting.setTotal(jdbcTemplate.queryForObject(countsql, Integer.class));
}
}
//判断方言,获取分页sql
if (pageAutoDialect.getDelegate()!=null) {
executeSql = pageAutoDialect.getDelegate().getPageSql(executeSql,pageSetting);
- logger.info("page executeSql===>"+executeSql);
+ logger.info("page executeSql===> "+executeSql);
}
//executeSql = MiniDaoUtil.createPageSql(dbType, executeSql, page, rows);
}
diff --git a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/parser/SqlServerParser.java b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/parser/SqlServerParser.java
index 192bf47..02b8baa 100644
--- a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/parser/SqlServerParser.java
+++ b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/parser/SqlServerParser.java
@@ -1,5 +1,6 @@
package org.jeecgframework.minidao.pagehelper.parser;
+import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.expression.Alias;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.LongValue;
@@ -9,9 +10,13 @@
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.select.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jeecgframework.minidao.pagehelper.PageException;
import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* 将sqlserver查询语句转换为分页语句
@@ -27,6 +32,7 @@
* 该类设计为一个独立的工具类,依赖jsqlparser,可以独立使用
*/
public class SqlServerParser {
+ private static final Log logger = LogFactory.getLog(SqlServerParser.class);
//开始行号
public static final String START_ROW = String.valueOf(Long.MIN_VALUE);
//结束行号
@@ -46,6 +52,14 @@ public class SqlServerParser {
//别名前缀
protected static final String PAGE_COLUMN_ALIAS_PREFIX = "ROW_ALIAS_";
+ /**
+ * 匹配:user.name这样的参数表达式
+ */
+ public static Pattern dynamic = Pattern.compile(":[ tnx0Bfr]*[0-9a-z.A-Z_]+");
+ public static String DIAN = ".";
+ public static String DIAN_TMP = "@@@";
+
+
//静态方法处理
static {
TOP100_PERCENT = new Top();
@@ -75,10 +89,29 @@ public String convertToPageSql(String sql) {
public String convertToPageSql(String sql, Integer offset, Integer limit) {
//解析SQL
Statement stmt;
+ List sqList = null;
+ String sqlOriginal = sql;
+
try {
stmt = CCJSqlParserUtil.parse(sql);
- } catch (Throwable e) {
- throw new PageException("不支持该SQL转换为分页查询!", e);
+ } catch (JSQLParserException e) {
+ //--------带点处理---------------------------------------------------------------------------------------
+ try {
+ //如果是 :user.name 类似含点的表达式,特殊处理下sql再解析
+ if (e.toString().indexOf(DIAN) != -1) {
+ sqList = getKeyListByContent(sql);
+ for (String s : sqList) {
+ sql = sql.replace(s, s.replace(DIAN, DIAN_TMP));
+ }
+ logger.debug(" --- JSQLParser with DIAN --- convert begin sql = " + sql);
+ stmt = CCJSqlParserUtil.parse(sql);
+ } else {
+ throw new PageException("不支持该SQL转换为分页查询!", e);
+ }
+ } catch (JSQLParserException e1) {
+ throw new PageException("不支持该SQL转换为分页查询!", e);
+ }
+ //----------带点处理-------------------------------------------------------------------------------------
}
if (!(stmt instanceof Select)) {
throw new PageException("分页语句必须是Select查询!");
@@ -93,9 +126,36 @@ public String convertToPageSql(String sql, Integer offset, Integer limit) {
if (limit != null) {
pageSql = pageSql.replace(PAGE_SIZE, String.valueOf(limit));
}
+
+ //------带点处理-----------------------------------------------------------------------------------------
+ //如果是 :user.name 类似含点的表达式,特殊处理下sql再解析
+ if (sqList != null) {
+ for (String s : sqList) {
+ pageSql = pageSql.replace(s.replace(DIAN, DIAN_TMP), s.replace(DIAN_TMP, DIAN));
+ }
+ logger.debug(" --- JSQLParser with DIAN --- convert end sql = " + pageSql);
+ }
+ //-----带点处理-------------------------------------------------------------------------------------------
return pageSql;
}
+ /**
+ * 按照动态内容的参数出现顺序,将参数放到List中
+ *
+ * @param content
+ * @return
+ */
+ public static List getKeyListByContent(String content) {
+ Set paramSet = new LinkedHashSet<>();
+ Matcher m = dynamic.matcher(content);
+ while (m.find()) {
+ if (m.group() != null && m.group().indexOf(DIAN) != -1) {
+ paramSet.add(m.group());
+ }
+ }
+ return new ArrayList<>(paramSet);
+ }
+
/**
* 获取一个外层包装的TOP查询
*
diff --git a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/util/FreemarkerParseFactory.java b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/util/FreemarkerParseFactory.java
index dc2cae5..dc8ac62 100644
--- a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/util/FreemarkerParseFactory.java
+++ b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/util/FreemarkerParseFactory.java
@@ -88,6 +88,10 @@ public static boolean isExistTemplate(String tplName) throws Exception {
public static String parseTemplate(String tplName, Map paras) {
try {
logger.debug(" minidao sql templdate : "+tplName);
+ //jeecg : Minidao报错“Template java/lang/Object_toString.sql not found”的解决方案
+ if("java/lang/Object_toString.sql".endsWith(tplName)){
+ return "";
+ }
StringWriter swriter = new StringWriter();
Template mytpl = _tplConfig.getTemplate(tplName, ENCODE);
if(paras.containsKey(MINI_DAO_FORMAT)){
diff --git a/minidao-pe-spring-boot-starter/pom.xml b/minidao-pe-spring-boot-starter/pom.xml
index 4a51b39..e656e0d 100644
--- a/minidao-pe-spring-boot-starter/pom.xml
+++ b/minidao-pe-spring-boot-starter/pom.xml
@@ -3,7 +3,7 @@
4.0.0
org.jeecgframework
minidao-spring-boot-starter
- 1.8.23
+ 1.8.3
org.springframework.boot
spring-boot-starter-parent
@@ -30,7 +30,7 @@
- 1.8.23
+ 1.8.3
1.1.9