当前位置:   article > 正文

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

encountered unexpected token: "(" "(

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如下:

  1. <!-- 查询用户分页数据 -->
  2. <select id="getOwnerStatisticsPage" resultType="com.susu.Result" parameterType="com.susu.Query">
  3. SELECT
  4. pid,
  5. sum(online = 1) AS onlinesum,
  6. count(*) sum
  7. FROM
  8. table_name
  9. WHERE 1 = 1
  10. <if test="query.beginTime != null and query.beginTime != ''">
  11. AND create_time &gt;= #{query.beginTime}
  12. </if>
  13. <if test="query.stopTime != null and query.stopTime != ''">
  14. AND create_time &lt; #{query.stopTime}
  15. </if>
  16. GROUP BY
  17. pid
  18. ORDER BY
  19. pid ASC
  20. LIMIT #{query.currPage},#{query.pageSize}
  21. </select>
  1. Mapper层接口方法:
  2. List<Result> getPage(@Param("query") Query query);

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/894195
推荐阅读
相关标签
  

闽ICP备14008679号