ParseException: Encountered unexpected token: “(“ “(“ at line 3, column 6.

2年前 (2022) 程序员胖胖胖虎阿
327 0 0

springboot项目整合mybatis-plus项目,编写test,执行service调用dao中的xml写的sql的时候,项目报错:

Caused by: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Failed to process, please exclude the tableName or statementId.

Caused by: net.sf.jsqlparser.JSQLParserException
    at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatements(CCJSqlParserUtil.java:128)
    at com.baomidou.mybatisplus.core.parser.AbstractJsqlParser.parser(AbstractJsqlParser.java:60)
    ... 61 more
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "(" "("
    at line 3, column 6.

Was expecting one of:

    "&"
    ","
    "::"
    ";"
    "<<"
    ">>"
    "ACTION"
    "ANY"
    "AS"
    "BYTE"
    "CASCADE"
    "CAST"
    "CHAR"
    "COLLATE"
    "COLUMN"
    "COLUMNS"
    "COMMENT"
    "COMMIT"
    "CONNECT"
    "DESCRIBE"
    "DO"
    "ENABLE"
    "END"
    "EXCEPT"
    "EXTRACT"
    "FIRST"
    "FN"
    "FOLLOWING"
    "FOR"
    "FROM"
    "GROUP"
    "HAVING"
    "INDEX"
    "INSERT"
    "INTERSECT"
    "INTERVAL"
    "INTO"
    "ISNULL"
    "KEY"
    "LAST"
    "MATERIALIZED"
    "MINUS"
    "NEXTVAL"
    "NO"
    "NULLS"
    "OPEN"
    "ORDER"
    "OVER"
    "PARTITION"
    "PATH"
    "PERCENT"
    "PRECISION"
    "PRIMARY"
    "PRIOR"
    "RANGE"
    "REPLACE"
    "ROW"
    "ROWS"
    "SEPARATOR"
    "SIBLINGS"
    "START"
    "TABLE"
    "TEMP"
    "TEMPORARY"
    "TOP"
    "TRUNCATE"
    "TYPE"
    "UNION"
    "UNSIGNED"
    "VALUE"
    "VALUES"
    "WHERE"
    "WINDOW"
    "XML"
    "ZONE"
    "^"
    "|"
    <EOF>
    <K_DATETIMELITERAL>
    <K_DATE_LITERAL>
    <S_CHAR_LITERAL>
    <S_IDENTIFIER>
    <S_QUOTED_IDENTIFIER>

    at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:20951)
    at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:20798)
    at net.sf.jsqlparser.parser.CCJSqlParser.Statements(CCJSqlParser.java:562)
    at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatements(CCJSqlParserUtil.java:126)
    ... 62 more

Disconnected from the target VM, address: '127.0.0.1:59287', transport: 'socket'

Process finished with exit code -1
[community-platform]2022-03-02 16:11:17,880|INFO|192.168.1.141[community-platform]2022-03-02 16:11:17,884|INFO|192.168.1.141[community-platform]2022-03-02 16:11:17,887|INFO|192.168.1.141[community-platform]2022-03-02 16:11:17,898|INFO|192.168.1.141[community-platform]2022-03-02 16:11:17,920|INFO|192.168.1.141

我的mapper的xml如下:

<!-- 查询用户分页数据 -->
	<select id="getOwnerStatisticsPage" resultType="com.susu.Result" parameterType="com.susu.Query">
		SELECT
		pid,
		sum(online = 1) AS onlinesum,
		count(*) sum
		FROM
		table_name
		WHERE 1 = 1
		<if test="query.beginTime != null and query.beginTime != ''">
			AND create_time &gt;= #{query.beginTime}
		</if>
		<if test="query.stopTime != null and query.stopTime != ''">
			AND create_time &lt; #{query.stopTime}
		</if>
		GROUP BY
		pid
		ORDER BY
		pid ASC
		LIMIT #{query.currPage},#{query.pageSize}
	</select>
Mapper层接口方法:

List<Result> getPage(@Param("query") Query query);

我们可以看到,是解析异常,那么可以在Mapper层接口方法上加上如下注解,排除sql解析

@SqlParser(filter=true)
List<Result> getPage(@Param("query") Query query);

相关文章

暂无评论

暂无评论...