错误:Could not set parameters for mapping: ParameterMapping{property=‘startTime‘, mode=IN, javaType=cl

Spring Boot MyBatis Mapper报错:

Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property=‘startTime’, mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId=‘null’, jdbcTypeName=‘null’, expression=‘null’}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #7 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #7 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (7 > number of parameters, which is 6).
at com.baomidou.mybatisplus.MybatisDefaultParameterHandler.setParameters(MybatisDefaultParameterHandler.java:276)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:93)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:64)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:326)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at sun.reflect.GeneratedMethodAccessor83.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
… 22 common frames omitted
Caused by: org.apache.ibatis.type.TypeException: Error setting non null for parameter #7 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #7 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (7 > number of parameters, which is 6).
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:55)
at com.baomidou.mybatisplus.MybatisDefaultParameterHandler.setParameters(MybatisDefaultParameterHandler.java:274)
… 36 common frames omitted
Caused by: org.apache.ibatis.type.TypeException: Error setting non null for parameter #7 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (7 > number of parameters, which is 6).
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:55)
at org.apache.ibatis.type.UnknownTypeHandler.setNonNullParameter(UnknownTypeHandler.java:45)
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:53)
… 37 common frames omitted
Caused by: java.sql.SQLException: Parameter index out of range (7 > number of parameters, which is 6).

在这里插入代码片

mapper中sql

...省略...
where a.ticket_state in ('售票','解锁','检票')
            AND (
                ( a.sell_time >= '2023-05-04 00:00:00' AND a.sell_time <'2023-05-04 23:59:59' )
                OR ( a.leave_date>= DATE_FORMAT( '2023-05-04 00:00:00','%Y-%m-%d') and a.leave_date < DATE_FORMAT( '2023-05-04 23:59:59','%Y-%m-%d') and
                concat( a.leave_date, ' ', a.fact_start_time ) >= '2023-05-04 00:00:00'
                AND concat( a.leave_date, ' ', a.fact_start_time ) < '2023-05-04 23:59:59'
                )
            )
                -- and concat(a.leave_date,' ',a.fact_start_time) >= #{startTime}
                -- and concat(a.leave_date,' ',a.fact_start_time) &lt; #{endTime}
                -- and a.sell_time >= #{startTime}
                -- and a.sell_time  &lt; #{endTime}
         GROUP BY a.id

分析

看到Could not set parameters for mapping,一直以为是mapper里的sql语法错了,检查了好久也没发现sql有问题,在Parameter index out of range (7 > number of parameters, which is 6)中 告诉我有7个地方引用参数 但是只定义了六个,想了一下,那不只能是注释中的也算上了吗,没错,就是注释的问题,把注释删掉,问题解决

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值