【mybatis-plus报错】exceptionnet.sf.jsqlparser.parser.ParseException: ...token: “?“ “?“

Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4ee5b2d9] was not registered for synchronization because synchronization is not active
optimize this sql to a count sql has exception, sql:"select * from user where name like "%"?"%"", exception:
net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "?" "?"
    at line 1, column 39.

Was expecting one of:

    "&"
    "&&"
    "::"
    ";"
    "<<"
    ">>"
    "AND"
    "COLLATE"
    "CONNECT"
    "ESCAPE"
    "EXCEPT"
    "FOR"
    "GROUP"
    "HAVING"
    "INTERSECT"
    "MINUS"
    "ORDER"
    "START"
    "UNION"
    "["
    "^"
    "|"
    <EOF>

2022-08-10 18:34:07.776  INFO 58012 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2022-08-10 18:34:08.003  INFO 58012 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
JDBC Connection [HikariProxyConnection@14838518 wrapping com.mysql.cj.jdbc.ConnectionImpl@44065156] will not be managed by Spring
==>  Preparing: SELECT COUNT(*) FROM (select * from user where name like "%"?"%") TOTAL
==> Parameters: n(String)
<==    Columns: COUNT(*)
<==        Row: 3
<==      Total: 1
==>  Preparing: select * from user where name like "%"?"%" LIMIT ?,?
==> Parameters: n(String), 2(Long), 2(Long)
<==    Columns: id, name, age, email, create_time, update_time, is_deleted
<==        Row: 1557282050531258369, hellen, 18, null, 2022-08-10 16:25:48, 2022-08-10 16:25:48, 0
<==      Total: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4ee5b2d9]
2
3

如图,但是不会影响运行结果,最后解决办法如下:

  • 方法1 “%”#{name}“%” mapper中的字符串拼接用concat(‘%’,#{name},‘%’)
  • 方法2 new一个page,page.setOptimizeCountSql(false);
  • 参考博客
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值