Skip to content

Commit

Permalink
minidao 1.8.3版本发布
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangdaiscott committed Aug 8, 2021
1 parent a3f4361 commit 1d4589d
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 13 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MiniDao
=======
当前最新版本: 1.8.23 (发布日期:20210728
当前最新版本: 1.8.3 (发布日期:20210809



Expand All @@ -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)
```
<dependency>
<groupId>org.jeecgframework</groupId>
<artifactId>minidao-pe</artifactId>
<version>1.8.3</version>
</dependency>
```
[文档](https://minidao.mydoc.io/?t=336070)

#### 方式二:springmvc与minidao集成
[https://minidao.mydoc.io/?t=293634](https://minidao.mydoc.io/?t=293634)
```
<dependency>
<groupId>org.jeecgframework</groupId>
<artifactId>minidao-spring-boot-starter</artifactId>
<version>1.8.3</version>
</dependency>
```

[文档](https://minidao.mydoc.io/?t=293634)


Expand Down
2 changes: 1 addition & 1 deletion minidao-pe-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


<properties>
<minidao.version>1.8.23</minidao.version>
<minidao.version>1.8.3</minidao.version>
<junit.version>4.13.1</junit.version>
<springframework.version>5.2.10.RELEASE</springframework.version>
<!-- 数据库驱动 -->
Expand Down
2 changes: 1 addition & 1 deletion minidao-pe-framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.jeecgframework</groupId>
<artifactId>minidao-pe</artifactId>
<version>1.8.23</version>
<version>1.8.3</version>
<packaging>jar</packaging>

<name>minidao-pe</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> sqlMap = installPlaceholderSqlParam(executeSql, sqlParamsMap);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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查询语句转换为分页语句<br>
Expand All @@ -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);
//结束行号
Expand All @@ -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();
Expand Down Expand Up @@ -75,10 +89,29 @@ public String convertToPageSql(String sql) {
public String convertToPageSql(String sql, Integer offset, Integer limit) {
//解析SQL
Statement stmt;
List<String> 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查询!");
Expand All @@ -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<String> getKeyListByContent(String content) {
Set<String> 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查询
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public static boolean isExistTemplate(String tplName) throws Exception {
public static String parseTemplate(String tplName, Map<String, Object> 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)){
Expand Down
4 changes: 2 additions & 2 deletions minidao-pe-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.jeecgframework</groupId>
<artifactId>minidao-spring-boot-starter</artifactId>
<version>1.8.23</version>
<version>1.8.3</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
Expand All @@ -30,7 +30,7 @@

<properties>
<!-- minidao -->
<minidao.version>1.8.23</minidao.version>
<minidao.version>1.8.3</minidao.version>
<druid.version>1.1.9</druid.version>
</properties>

Expand Down

0 comments on commit 1d4589d

Please sign in to comment.