mybatis查询报错
报错信息如下:
nested exception is org.apache.ibatis.type.TypeException: JDBC requires that the JdbcType must be specified for all nullable parameters. org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: JDBC requires that the JdbcType must be specified for all nullable parameters. at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365) at com.sun.proxy.$Proxy71.selectList(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:195) at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:124) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:90) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40) at com.sun.proxy.$Proxy375.selectByPage(Unknown Source) at
问题原因
原来我的qysxLong
属性是string类型
的,赋值
的时候赋值了一个空字符串
,所以报的上面的错,你检查一下是否也是这样的原因
and ((a.qysx =#{qysxLong} and m.actflag = 0) or
(m.actflag = 1))
解决方案
我把qysxLong改成了int类型
,并且做了判断,不为0的时候再加这个查询条件
还有一种情况就是像这种,如果proLineList数组的长度为0,也会报上面的错,所以我们需要在多加一个判断
proLineList.size >0,完整版代码如下:
有问题的代码:
and a.qysx in '${proLine}'::int ## 修改后的代码: and a.qysx in '${proLine}'::int总结
如果你where条件中的字段类型与字段值的类型不匹配,也会报这个错误,多检查一下,希望我的文章可以解决掉你的问题,不懂得或者还是没有解决的私信或留言