当前使用版本(必填,否则不予处理)

3.4.2

该问题是如何引起的?(确定最新版也有问题再提!!!)

重现步骤(如果有就写完整)

伪代码

Page page = new Page<>(1, 10); page = entityService.page(page, Wrappers.lambdaQuery .apply("TO_DAYS(create_time) = TO_DAYS({0})", "2023-10-13"));

报错信息

Error querying database. Cause: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Integer

1697185416872

Comment From: nieqiurong

能提供一个复现小工程上来排查?

Comment From: fatcatmaster

能提供一个复现小工程上来排查?

经过代码跟踪,发现是因为我引入mybatis-plus依赖的同时,也引入了如下依赖用于分表分库 `

    <dependency>
        <groupId>org.apache.shardingsphere</groupId>
        <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
        <version>4.1.1</version>
    </dependency>

` 满足上述条件后,使用 MP 的分页API和apply+占位符的方法就会报错 复现的工程代码地址:https://github.com/fatcatmaster/feedback

Comment From: nieqiurong

sharding-jdbc

能提供一个复现小工程上来排查?

经过代码跟踪,发现是因为我引入mybatis-plus依赖的同时,也引入了如下依赖用于分表分库 `

<dependency> <groupId>org.apache.shardingsphere</groupId> <artifactId>sharding-jdbc-spring-boot-starter</artifactId> <version>4.1.1</version> </dependency>

` 满足上述条件后,使用 MP 的分页API和apply+占位符的方法就会报错 复现的工程代码地址:https://github.com/fatcatmaster/feedback

MyBatis-Plus 分页API使用 apply+占位符,报数据类型转换错误

sharding-jdbc不了解,你检查一下你用法是否正确,只是看看到他解析出来的limit参数提取的错了,你写原生mybatis语句他也是这个强转错误.

Comment From: fatcatmaster

跟踪源码,发现是 shardingsphere 参数设置错误,针对带有limit的sql,shardingsphere默认只有limit后会存在占位符,因为setLimit 时默认从参数列表的0号位开始,每次getValue后自增1,如果存在下一个占位符就继续getValue然后增1,但是参数列表中最后的1位或者两位才是limit正确的参数,所以可以考虑 setLimit 时从后往前设置

Comment From: ES1993

怎么解决