mybatis-plus使用聚合函数报错---------net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "**" "**"
错误日志:
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "with" "WITH" at line 62, column 20. Was expecting one of: "&" "::" ";" "<<" ">>" "COLLATE" "EMIT" "HAVING" "[" "^" "|" <EOF> at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:31234) at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:31067) at net.sf.jsqlparser.parser.CCJSqlParser.Statement(CCJSqlParser.java:163) at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatement(CCJSqlParserUtil.java:188) at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:63) at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:38) at com.baomidou.mybatisplus.extension.parser.JsqlParserSupport.parserSingle(JsqlParserSupport.java:49) ... 56 more
部分代码:
mapper.xml
<select id="tt" resultType="String"> select ifnull(billcode, '合计') billcode from ( select * from ( select A.id, A.billcode, A.billamt, A.bankcode, d.depart_name, A.billtype, A.billstatus, A.propsrinfo_name, A.propsrinfo_acctid, A.tranamt, A.trandate, A.bartamt, A.next_bankname, A.negtbl, A.drawdate, A.duedate, A.draweracct_name, A.draweracct_acctid, A.draweracct_banknum, A.draweracct_bankname, A.payeeacct_name, A.payeeacct_acctid, A.payeeacct_banknum, A.payeeacct_bankname, A.acptracct_name, A.acptracct_acctid, A.acptracct_banknum, A.acptracct_bankname, B.tranddate, B.trandamt, B.whendate, B.RETURNAMT, B.RETURNDATE, A.SYS_ORG_CODE, OPERFLAG, DISPLACEFLAG from BUS_BILL_INFO_CUST A left join BUS_BILL_PAYINFO B on A.ID = B.BILLINFOID left join sys_depart d on a.SYS_ORG_CODE = d.org_code order by A.CREATE_TIME desc )u ) y where OPERFLAG = 'D' and DISPLACEFLAG = '0' and y.id = '286664a968714baa9800a5712e26f1cb' group by y.billcode with rollup </select>
mapper接口:
List<String> tt();
问题原因:
原因是因为mybatisplus不识别sql查询语句中的返回使用函数,例如
group by y.billcode with rollup聚合函数
解决办法:
增加@InterceptorIgnore(tenantLine = "true"),网上也有说增加
@SqlParser(filter = true)(没试,应该也可以)
@InterceptorIgnore(tenantLine = "true")
List<String> tt();