nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping

现象

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='streetId', 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 #1 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 #1 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 (1 > number of parameters, which is 0).
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
	at com.sun.proxy.$Proxy235.selectOne(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:160)
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:89)
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
	at com.sun.proxy.$Proxy309.countRepair(Unknown Source)
	at com.jnh.icloud.wc.service.impl.WCBigScreenServiceImpl.streetStatistics(WCBigScreenServiceImpl.java:44)
	at com.jnh.icloud.wc.controller.WCBigScreenController.streetStatistics(WCBigScreenController.java:32)

原因分析

请检查一下变量上是否加了’'。

错误的代码如下:

   <select id="countRepair"  resultType="java.lang.Integer">
        select count(*) from wc_repair where country_id in (select id from sys_area where pid='#{streetId}')
    select>

请注意这里的'#{streetId}'是错误的写法,应该去掉’'。正确的如下:

 <select id="countRepair"  resultType="java.lang.Integer">
        select count(*) from wc_repair where country_id in (select id from sys_area where pid=#{streetId})
    select>

你可能感兴趣的:(java,mybatis)