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);
- 参考博客