当前使用版本(必填,否则不予处理)
3.5.1
该问题是如何引起的?(确定最新版也有问题再提!!!)
使用自带的updateById方法,生成的sql如下UPDATE om_calendar_act_info SET action_calendar_id =?,act_time =?,sys_code =?,apply =?,act_name =?,begin_date =?,end_date =?,STATUS =?,is_commit =?,activity_details =?,images =?,materials =?,hr_bh =?,hr_name =?,create_time =?,update_user =?,update_time =? WHEREid =? AND del =0 ,一开始执行的时候会报错如下Encountered unexpected token: "apply" "APPLY",于是我提了一个issue ,但是我根据回复修改后,又出现如下问题Encountered unexpected token: "\n\n\n" <ST_SEMICOLON>。我将版本改为3.5.3.1后还是会出现该问题
重现步骤(如果有就写完整)
报错信息
- Encountered unexpected token: "apply" "APPLY"
- Encountered unexpected token: "\n\n\n"
Comment From: manticore-projects
Greetings!
Starting with JSQLParser 4.6, two empty lines .*\n\n\n terminate a statement. (And I still will need a good argument why anyone would need 2 empty rows within one statement.)
select 1 from dual
select 2 from dual
gives 2 statements (without typing semicolons ;)
I will appreciate your consideration, since we receive reports about MyBatis Plus' auto-generated statements. Thank you.
Comment From: bubble2121
同遇到这个问题,暂时换回4.4,把关键字换换,先用着
Comment From: nieqiurong
暂时可以通过配置去除一下,后面的版本解决.
mybatis-plus:
configuration:
shrink-whitespaces-in-sql: true
Comment From: qq592304796
暂时可以通过配置去除一下,后面的版本解决.
yaml mybatis-plus: configuration: shrink-whitespaces-in-sql: true
https://github.com/baomidou/mybatis-plus/issues/5484
originalSql.replaceAll("(\\r?\\n){2,}", "$1")
使用StringTokenizer如果SQL中有注释什么的会有异常。
Comment From: krystal9003
when mybatis-plus generate updateById method,it use "\n" to split every properties. so when the propertie is null, the dynamic sql will appear \n\n\n.So I suggeset modify the "\n" to "\n ".
Comment From: GuanWeiGit
二开 org.apache.ibatis.builder.SqlSourceBuilder.parse
//将连续的空行替换为一个空行 originalSql = originalSql.replaceAll("\n+", "\n");
`
public SqlSource parse(String originalSql, Class<?> parameterType, Map
ParameterMappingTokenHandler handler = new ParameterMappingTokenHandler(configuration, parameterType, additionalParameters);
GenericTokenParser parser = new GenericTokenParser("#{", "}", handler);
String sql;
//TODO 将连续的空行替换为一个空行
originalSql = originalSql.replaceAll("\\n+", "\n");
if (configuration.isShrinkWhitespacesInSql()) {
sql = parser.parse(removeExtraWhitespaces(originalSql));
} else {
sql = parser.parse(originalSql);
}
return new StaticSqlSource(configuration, sql, handler.getParameterMappings());
}`
或者 (不推荐) configuration: shrink-whitespaces-in-sql: true
Comment From: manticore-projects
Again, you can call CCJSqlParserUtil.sanitizeSingleSql( sqlStr) to clean your statements properly.
Details see here: https://github.com/JSQLParser/JSqlParser/issues/1988#issuecomment-2063941501