diff --git a/minidao-pe-example/pom.xml b/minidao-pe-example/pom.xml index 8c7f0ee..9d6d7c8 100644 --- a/minidao-pe-example/pom.xml +++ b/minidao-pe-example/pom.xml @@ -8,9 +8,9 @@ - 1.8.3 + 1.9.0 4.13.1 - 5.2.10.RELEASE + 5.3.18 8.0.21 42.2.6 diff --git a/minidao-pe-example/src/main/java/examples/entity/Employee.java b/minidao-pe-example/src/main/java/examples/entity/Employee.java index 0eddf3b..e26ebbc 100644 --- a/minidao-pe-example/src/main/java/examples/entity/Employee.java +++ b/minidao-pe-example/src/main/java/examples/entity/Employee.java @@ -35,7 +35,7 @@ public class Employee implements Serializable { *主键 *@TableId 支持uuid(默认)\AUTO(自增)\ID_WORKER(雪花ID)\ID_SEQ(序列seq,必须配置seqName) */ - @TableId(type = IdType.UUID) + @TableId(type = IdType.AUTO) private String id; /** *雇员编号 diff --git a/minidao-pe-example/src/main/java/examples/interceptor/MinidaoInterceptor.java b/minidao-pe-example/src/main/java/examples/interceptor/MinidaoInterceptor.java index ecf0018..0242a1d 100644 --- a/minidao-pe-example/src/main/java/examples/interceptor/MinidaoInterceptor.java +++ b/minidao-pe-example/src/main/java/examples/interceptor/MinidaoInterceptor.java @@ -20,13 +20,13 @@ public class MinidaoInterceptor implements EmptyInterceptor { public boolean onInsert(Field[] fields, Object obj) { Map map = new HashMap(); for (int j = 0; j < fields.length; j++) { - fields[j].setAccessible(true); + //fields[j].setAccessible(true); String fieldName = fields[j].getName(); if ("createDate".equals(fieldName)) { map.put("createDate", new Date()); } if ("createBy".equals(fieldName)) { - map.put("createBy", "scott"); + map.put("createBy", "admin"); } } try { @@ -42,7 +42,7 @@ public boolean onInsert(Field[] fields, Object obj) { public boolean onUpdate(Field[] fields, Object obj) { Map map = new HashMap(); for (int j = 0; j < fields.length; j++) { - fields[j].setAccessible(true); + //fields[j].setAccessible(true); String fieldName = fields[j].getName(); if ("updateBy".equals(fieldName)) { map.put("updateBy", "scott"); diff --git a/minidao-pe-example/src/test/java/test/ClientDaoIdNative.java b/minidao-pe-example/src/test/java/test/ClientDaoIdNative.java index bd21b07..99302b4 100644 --- a/minidao-pe-example/src/test/java/test/ClientDaoIdNative.java +++ b/minidao-pe-example/src/test/java/test/ClientDaoIdNative.java @@ -19,11 +19,11 @@ public static void main(String args[]) { EmployeeDao employeeDao = (EmployeeDao) factory.getBean("employeeDao"); Employee employee = new Employee(); - employee.setEmpno("200"); - employee.setName("scott"); + employee.setEmpno("2001"); + employee.setName("scott1"); employee.setBirthday(new Date()); - employee.setAge(20); - employee.setSalary(new BigDecimal(88888)); + employee.setAge(21); + employee.setSalary(new BigDecimal(88888111)); employeeDao.insertNative(employee); System.out.println("对象值:"+employee.toString()); } diff --git a/minidao-pe-example/src/test/java/test/ClientDaoPageTest.java b/minidao-pe-example/src/test/java/test/ClientDaoPageTest.java new file mode 100644 index 0000000..5f9ad01 --- /dev/null +++ b/minidao-pe-example/src/test/java/test/ClientDaoPageTest.java @@ -0,0 +1,36 @@ +package test; + +import com.alibaba.druid.support.logging.Log; +import com.alibaba.druid.support.logging.LogFactory; +import com.alibaba.druid.util.JdbcUtils; +import examples.dao.EmployeeDao; +import examples.entity.Employee; +import org.jeecgframework.minidao.pojo.MiniDaoPage; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * 测试ID主键规则: Int 自增 + * (注意:测试该方法需要把数据库ID类型改成int,自增) + */ +public class ClientDaoPageTest { + private final static Log log = LogFactory.getLog(ClientDaoPageTest.class); + public static void main(String args[]) { + BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml"); + EmployeeDao employeeDao = (EmployeeDao) factory.getBean("employeeDao"); + + //第一页数据 + MiniDaoPage pageList1 = employeeDao.getAll(new Employee(),2,10); + log.info("getTotal1 = "+pageList1.getTotal()); + log.info("getPages1 = "+pageList1.getPages()); + + + //第二页数据 + MiniDaoPage pageList2 = employeeDao.getAll(new Employee(),2,10); + log.info("getTotal2 = "+pageList2.getTotal()); + log.info("getPages2 = "+pageList2.getPages()); + } +} diff --git a/minidao-pe-framework/pom.xml b/minidao-pe-framework/pom.xml index b417a8c..026b4a1 100644 --- a/minidao-pe-framework/pom.xml +++ b/minidao-pe-framework/pom.xml @@ -4,7 +4,7 @@ org.jeecgframework minidao-pe - 1.8.3 + 1.9.0 jar minidao-pe @@ -31,14 +31,14 @@ 1.9.6 - 3.2.1 + 3.2.2 2.3.30 - 2.6.11 + 3.2.21 1.2 3.12.0 - 5.2.10.RELEASE - 3.15.0-GA - 3.2 + 5.3.18 + 3.25.0-GA + 4.3 @@ -91,9 +91,15 @@ runtime - opensymphony + ognl ognl ${ognl.version} + + + javassist + org.javassist + + org.javassist 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 9a62431..aa8e79b 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 @@ -32,6 +32,7 @@ import org.jeecgframework.minidao.util.*; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Lazy; import org.springframework.dao.EmptyResultDataAccessException; @@ -43,6 +44,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.KeyHolder; +import javax.annotation.Resource; import javax.sql.DataSource; /** @@ -57,7 +59,12 @@ @SuppressWarnings("rawtypes") public class MiniDaoHandler implements InvocationHandler { private static final Log logger = LogFactory.getLog(MiniDaoHandler.class); - + + /**自定义的数据源*/ + @Autowired(required = false) + @Qualifier("minidaoDataSource") + public DataSource dataSource; + @Autowired @Lazy private JdbcTemplate jdbcTemplate; @@ -284,7 +291,15 @@ public JdbcTemplate getJdbcTemplate() { jdbcTemplate = new JdbcTemplate(multDataSourceMap.get(keyOfTheFirst)); } } - } + }else{ + //update-begin--Author:wangshuai--Date:20211018--for: 用户自定义的数据源是否为空,不为空则走用户自定义的数据源 + if(null != dataSource){ + namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); + } + //update-end--Author:wangshuai--Date:20211018--for: 用户自定义的数据源是否为空,不为空则走用户自定义的数据源 + } + return jdbcTemplate; } @@ -322,7 +337,15 @@ private Object getReturnMinidaoResult(MiniDaoPage pageSetting, Method method, St jdbcTemplate = new JdbcTemplate(multDataSourceMap.get(keyOfTheFirst)); } } - } + }else{ + //update-begin--Author:wangshuai--Date:20211018--for: 用户自定义的数据源是否为空,不为空则走用户自定义的数据源 + if(null!=dataSource){ + namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); + } + //update-end--Author:wangshuai--Date:20211018--for: 用户自定义的数据源是否为空,不为空则走用户自定义的数据源 + } + if(emptyInterceptor==null){ try { emptyInterceptor = applicationContext.getBean(EmptyInterceptor.class); @@ -556,18 +579,20 @@ private String installDaoMetaData(MiniDaoPage pageSetting, Method method, Map map = new HashMap(); for (int j = 0; j < fields.length; j++) { - fields[j].setAccessible(true); + //fields[j].setAccessible(true); String fieldName = fields[j].getName(); //1.获取所有的注解 TableId annotation = fields[j].getAnnotation(TableId.class); diff --git a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/aspect/MinidaoInterceptor.java b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/aspect/MinidaoInterceptor.java index 3d1e8d8..b94d115 100644 --- a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/aspect/MinidaoInterceptor.java +++ b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/aspect/MinidaoInterceptor.java @@ -15,7 +15,7 @@ public class MinidaoInterceptor implements EmptyInterceptor { public boolean onInsert(Field[] fields, Object obj) { Map map = new HashMap(); for (int j = 0; j < fields.length; j++) { - fields[j].setAccessible(true); + //fields[j].setAccessible(true); String fieldName = fields[j].getName(); if ("createBy".equals(fieldName)) { map.put("createBy", "scott"); diff --git a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/HsqldbDialect.java b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/HsqldbDialect.java index 82abe7d..e0a18c0 100644 --- a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/HsqldbDialect.java +++ b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/HsqldbDialect.java @@ -4,6 +4,7 @@ import org.jeecgframework.minidao.pojo.MiniDaoPage; import java.text.MessageFormat; +import java.util.Locale; /** * Hsqldb @@ -13,14 +14,29 @@ public class HsqldbDialect extends AbstractHelperDialect { @Override public String getPageSql(String sql, MiniDaoPage miniDaoPage) { StringBuilder sqlBuilder = new StringBuilder(sql.length() + 20); - sqlBuilder.append(sql); - String[] sqlParam = this.getPageParam(miniDaoPage); - if (Integer.valueOf(sqlParam[1]) > 0) { - sqlBuilder.append("\n LIMIT {1} "); - } - if (Integer.valueOf(sqlParam[0]) > 0) { - sqlBuilder.append("\n OFFSET {0} "); + //update-begin--Author:wangshuai--Date:20211201--for:判断Hsql是否包含limit或offset,包含用select包裹起来,不包含直接拼接 + if(sql.toUpperCase().contains("LIMIT") || sql.toUpperCase().contains("OFFSET")){ + String[] sqlParam = this.getPageParam(miniDaoPage); + sqlBuilder.append("SELECT * FROM ("); + sqlBuilder.append(sql); + sqlBuilder.append(") TMP_PAGE "); + if (Integer.valueOf(sqlParam[1]) > 0) { + sqlBuilder.append("\n LIMIT {1} "); + } + if (Integer.valueOf(sqlParam[0]) > 0) { + sqlBuilder.append("\n OFFSET {0} "); + } + }else{ + sqlBuilder.append(sql); + String[] sqlParam = this.getPageParam(miniDaoPage); + if (Integer.valueOf(sqlParam[1]) > 0) { + sqlBuilder.append("\n LIMIT {1} "); + } + if (Integer.valueOf(sqlParam[0]) > 0) { + sqlBuilder.append("\n OFFSET {0} "); + } } + //update-begin--Author:wangshuai--Date:20211201--for:判断mysql是否包含limit,包含用select包裹起来,不包含直接拼接 String newSql = sqlBuilder.toString(); newSql = super.format(newSql, super.getPageParam(miniDaoPage)); return newSql; diff --git a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/MySqlDialect.java b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/MySqlDialect.java index 1f238f3..a38d984 100644 --- a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/MySqlDialect.java +++ b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/MySqlDialect.java @@ -13,13 +13,26 @@ public class MySqlDialect extends AbstractHelperDialect { @Override public String getPageSql(String sql, MiniDaoPage miniDaoPage) { StringBuilder sqlBuilder = new StringBuilder(sql.length() + 14); - sqlBuilder.append(sql); String[] sqlParam = super.getPageParam(miniDaoPage); - if (Integer.valueOf(sqlParam[0]) == 0) { - sqlBuilder.append("\n LIMIT {1} "); - } else { - sqlBuilder.append("\n LIMIT {0}, {1} "); + //update-begin--Author:wangshuai--Date:20211201--for:判断mysql是否包含limit,包含用select包裹起来,不包含直接拼接 + if(sql.toUpperCase().contains("LIMIT")){ + sqlBuilder.append("SELECT * FROM ( "); + sqlBuilder.append(sql); + sqlBuilder.append(" ) TMP_PAGE "); + if (Integer.valueOf(sqlParam[0]) == 0) { + sqlBuilder.append("\n LIMIT {1}"); + } else { + sqlBuilder.append("\n LIMIT {0}, {1} "); + } + }else{ + sqlBuilder.append(sql); + if (Integer.valueOf(sqlParam[0]) == 0) { + sqlBuilder.append("\n LIMIT {1} "); + } else { + sqlBuilder.append("\n LIMIT {0}, {1} "); + } } + //update-end--Author:wangshuai--Date:20211201--for:判断mysql是否包含limit,包含用select包裹起来,不包含直接拼接 String newSql = sqlBuilder.toString(); newSql = super.format(newSql,sqlParam); return newSql; diff --git a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/OscarDialect.java b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/OscarDialect.java index 0808d18..9afd948 100644 --- a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/OscarDialect.java +++ b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/OscarDialect.java @@ -13,12 +13,24 @@ public class OscarDialect extends AbstractHelperDialect { @Override public String getPageSql(String sql, MiniDaoPage miniDaoPage) { StringBuilder sqlBuilder = new StringBuilder(sql.length() + 14); - sqlBuilder.append(sql); + //update-begin--Author:wangshuai--Date:20211201--for:判断oscar是否包含limit或OFFSET,包含用select包裹起来,不包含直接拼接 String[] sqlParam = this.getPageParam(miniDaoPage); - if (Integer.valueOf(sqlParam[0]) == 0) { - sqlBuilder.append("\n LIMIT {1} "); - } else { - sqlBuilder.append("\n LIMIT {1} OFFSET {0} "); + if(sql.toUpperCase().contains("LIMIT") || sql.toUpperCase().contains("OFFSET")){ + sqlBuilder.append("SELECT * FROM ("); + sqlBuilder.append(sql); + sqlBuilder.append(") TMP_PAGE "); + if (Integer.valueOf(sqlParam[0]) == 0) { + sqlBuilder.append("\n LIMIT {1} "); + }else{ + sqlBuilder.append("\n LIMIT {1} OFFSET {0} "); + } + }else{ + sqlBuilder.append(sql); + if (Integer.valueOf(sqlParam[0]) == 0) { + sqlBuilder.append("\n LIMIT {1} "); + } else { + sqlBuilder.append("\n LIMIT {1} OFFSET {0} "); + } } String newSql = sqlBuilder.toString(); newSql = super.format(newSql, super.getPageParam(miniDaoPage)); diff --git a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/PostgreSqlDialect.java b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/PostgreSqlDialect.java index 02e7f2c..4c18fd3 100644 --- a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/PostgreSqlDialect.java +++ b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/PostgreSqlDialect.java @@ -16,13 +16,26 @@ public class PostgreSqlDialect extends MySqlDialect { @Override public String getPageSql(String sql, MiniDaoPage miniDaoPage) { StringBuilder sqlStr = new StringBuilder(sql.length() + 17); - sqlStr.append(sql); + //update-begin--Author:wangshuai--Date:20211201--for:判断postgresql是否包含limit或OFFSET,包含用select包裹起来,不包含直接拼接 String[] sqlParam = super.getPageParam(miniDaoPage); - if (Integer.valueOf(sqlParam[0]) == 0) { - sqlStr.append(" LIMIT {1}"); - } else { - sqlStr.append(" OFFSET {0} LIMIT {1}"); + if(sql.toUpperCase().contains("LIMIT") || sql.toUpperCase().contains("OFFSET")){ + sqlStr.append("SELECT * FROM ("); + sqlStr.append(sql); + sqlStr.append(") TMP_PAGE "); + if (Integer.valueOf(sqlParam[0]) == 0) { + sqlStr.append(" LIMIT {1} "); + }else{ + sqlStr.append(" OFFSET {0} LIMIT {1}"); + } + }else{ + sqlStr.append(sql); + if (Integer.valueOf(sqlParam[0]) == 0) { + sqlStr.append(" LIMIT {1}"); + } else { + sqlStr.append(" OFFSET {0} LIMIT {1}"); + } } + //update-end--Author:wangshuai--Date:20211201--for:判断postgresql是否包含limit或OFFSET,包含用select包裹起来,不包含直接拼接 String newSql = sqlStr.toString(); newSql = super.format(newSql, super.getPageParam(miniDaoPage)); return newSql; diff --git a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/SqlServer2012Dialect.java b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/SqlServer2012Dialect.java index 3a66840..5dc362d 100644 --- a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/SqlServer2012Dialect.java +++ b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/dialect/helper/SqlServer2012Dialect.java @@ -12,8 +12,17 @@ public class SqlServer2012Dialect extends SqlServerDialect { @Override public String getPageSql(String sql, MiniDaoPage miniDaoPage) { StringBuilder sqlBuilder = new StringBuilder(sql.length() + 64); - sqlBuilder.append(sql); - sqlBuilder.append("\n OFFSET {0} ROWS FETCH NEXT {1} ROWS ONLY "); + //update-begin--Author:wangshuai--Date:20211201--for:判断sqlserver是否包含offset或next,包含用select包裹起来,不包含直接拼接 + if(sql.toUpperCase().contains("OFFSET") && sql.toUpperCase().contains("NEXT")){ + sqlBuilder.append("SELECT * FROM ("); + sqlBuilder.append(sql); + sqlBuilder.append(") TMP_PAGE "); + sqlBuilder.append("\n OFFSET {0} ROWS FETCH NEXT {1} ROWS ONLY "); + }else{ + sqlBuilder.append(sql); + sqlBuilder.append("\n OFFSET {0} ROWS FETCH NEXT {1} ROWS ONLY "); + } + //update-end--Author:wangshuai--Date:20211201--for:判断sqlserver是否包含offset或next,包含用select包裹起来,不包含直接拼接 String newSql = sqlBuilder.toString(); newSql = super.format(newSql, super.getPageParam(miniDaoPage)); return newSql; diff --git a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/parser/CountSqlParser.java b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/parser/CountSqlParser.java index 2ad1c51..822b673 100644 --- a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/parser/CountSqlParser.java +++ b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/parser/CountSqlParser.java @@ -341,8 +341,8 @@ public void processSelectBody(SelectBody selectBody) { processPlainSelect((PlainSelect) selectBody); } else if (selectBody instanceof WithItem) { WithItem withItem = (WithItem) selectBody; - if (withItem.getSelectBody() != null) { - processSelectBody(withItem.getSelectBody()); + if (withItem.getSubSelect().getSelectBody() != null) { + processSelectBody(withItem.getSubSelect().getSelectBody()); } } else { SetOperationList operationList = (SetOperationList) selectBody; @@ -388,7 +388,7 @@ public void processPlainSelect(PlainSelect plainSelect) { public void processWithItemsList(List withItemsList) { if (withItemsList != null && withItemsList.size() > 0) { for (WithItem item : withItemsList) { - processSelectBody(item.getSelectBody()); + processSelectBody(item.getSubSelect().getSelectBody()); } } } diff --git a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/parser/OrderByParser.java b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/parser/OrderByParser.java index e6795bd..22d23f7 100644 --- a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/parser/OrderByParser.java +++ b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/pagehelper/parser/OrderByParser.java @@ -55,8 +55,8 @@ public static List extraOrderBy(SelectBody selectBody) { return orderByElements; } else if (selectBody instanceof WithItem) { WithItem withItem = (WithItem) selectBody; - if (withItem.getSelectBody() != null) { - return extraOrderBy(withItem.getSelectBody()); + if (withItem.getSubSelect().getSelectBody() != null) { + return extraOrderBy(withItem.getSubSelect().getSelectBody()); } } else { SetOperationList operationList = (SetOperationList) selectBody; 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 02b8baa..5116781 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 @@ -93,7 +93,9 @@ public String convertToPageSql(String sql, Integer offset, Integer limit) { String sqlOriginal = sql; try { - stmt = CCJSqlParserUtil.parse(sql); + //update-begin---author:wangshuai ---date:20220215 for:[issues/I4STNJ]SQL Server表名关键字查询失败 + stmt = CCJSqlParserUtil.parse(sql,parser -> parser.withSquareBracketQuotation(true)); + //update-end---author:wangshuai ---date:20220215 for:[issues/I4STNJ]SQL Server表名关键字查询失败 } catch (JSQLParserException e) { //--------带点处理--------------------------------------------------------------------------------------- try { @@ -104,7 +106,7 @@ public String convertToPageSql(String sql, Integer offset, Integer limit) { sql = sql.replace(s, s.replace(DIAN, DIAN_TMP)); } logger.debug(" --- JSQLParser with DIAN --- convert begin sql = " + sql); - stmt = CCJSqlParserUtil.parse(sql); + stmt = CCJSqlParserUtil.parse(sql,parser -> parser.withSquareBracketQuotation(true)); } else { throw new PageException("不支持该SQL转换为分页查询!", e); } @@ -339,8 +341,8 @@ protected void processSelectBody(SelectBody selectBody, int level) { processPlainSelect((PlainSelect) selectBody, level + 1); } else if (selectBody instanceof WithItem) { WithItem withItem = (WithItem) selectBody; - if (withItem.getSelectBody() != null) { - processSelectBody(withItem.getSelectBody(), level + 1); + if (withItem.getSubSelect().getSelectBody() != null) { + processSelectBody(withItem.getSubSelect().getSelectBody(), level + 1); } } else { SetOperationList operationList = (SetOperationList) selectBody; diff --git a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/util/SqlServerParse.java b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/util/SqlServerParse.java index e1f002d..b6741d0 100644 --- a/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/util/SqlServerParse.java +++ b/minidao-pe-framework/src/main/java/org/jeecgframework/minidao/util/SqlServerParse.java @@ -37,7 +37,9 @@ public String removeOrderBy(String sql) throws JSQLParserException { Statement stmt = null; List sqList = null; try { - stmt = CCJSqlParserUtil.parse(sql); + //update-begin---author:wangshuai ---date:20220215 for:[issues/I4STNJ]SQL Server表名关键字查询失败 + stmt = CCJSqlParserUtil.parse(sql,parser -> parser.withSquareBracketQuotation(true)); + //update-end---author:wangshuai ---date:20220215 for:[issues/I4STNJ]SQL Server表名关键字查询失败 } catch (JSQLParserException e) { //--------------------------------------------------------------------------------------------- //如果是 :user.name 类似含点的表达式,特殊处理下sql再解析 @@ -46,7 +48,7 @@ public String removeOrderBy(String sql) throws JSQLParserException { for (String s : sqList) { sql = sql.replace(s, s.replace(DIAN, DIAN_TMP)); } - stmt = CCJSqlParserUtil.parse(sql); + stmt = CCJSqlParserUtil.parse(sql,parser -> parser.withSquareBracketQuotation(true)); } else { e.printStackTrace(); } @@ -92,8 +94,8 @@ public void processSelectBody(SelectBody selectBody) { processPlainSelect((PlainSelect) selectBody); } else if (selectBody instanceof WithItem) { WithItem withItem = (WithItem) selectBody; - if (withItem.getSelectBody() != null) { - processSelectBody(withItem.getSelectBody()); + if (withItem.getSubSelect().getSelectBody() != null) { + processSelectBody(withItem.getSubSelect().getSelectBody()); } } else { SetOperationList operationList = (SetOperationList) selectBody; @@ -104,8 +106,8 @@ public void processSelectBody(SelectBody selectBody) { processPlainSelect((PlainSelect) optSelect); } else if (optSelect instanceof WithItem) { WithItem withItem = (WithItem) optSelect; - if (withItem.getSelectBody() != null) { - processSelectBody(withItem.getSelectBody()); + if (withItem.getSubSelect().getSelectBody() != null) { + processSelectBody(withItem.getSubSelect().getSelectBody()); } } } diff --git a/minidao-pe-spring-boot-starter/pom.xml b/minidao-pe-spring-boot-starter/pom.xml index e656e0d..e669e47 100644 --- a/minidao-pe-spring-boot-starter/pom.xml +++ b/minidao-pe-spring-boot-starter/pom.xml @@ -3,11 +3,13 @@ 4.0.0 org.jeecgframework minidao-spring-boot-starter - 1.8.3 + 1.9.0 + jar + org.springframework.boot spring-boot-starter-parent - 2.3.5.RELEASE + 2.6.6 @@ -30,7 +32,7 @@ - 1.8.3 + 1.9.0 1.1.9