内容简介:使用mybatis动态sql进行遍历条件的时候报了下面这个错误:怎么找都没找到原因,最后发现这个sql之所以报错并不是这个sql写错了,而是传入的参数报错了,我认为参数是这个样子的:最后发现,参数是这个样子的的:
起因
使用mybatis动态 sql 进行遍历条件的时候报了下面这个错误:
Caused by: java.lang.IllegalStateException: Type handler was null on parameter mapping for property '__frch_item_0'. It was either not specified and/or could not be found for the javaType (com.test.Report) : jdbcType (null) combination. at org.apache.ibatis.mapping.ParameterMapping$Builder.validate (ParameterMapping.java:117) at org.apache.ibatis.mapping.ParameterMapping$Builder.build (ParameterMapping.java:104) at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.buildParameterMapping (SqlSourceBuilder.java:123) at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.handleToken (SqlSourceBuilder.java:67) at org.apache.ibatis.parsing.GenericTokenParser.parse (GenericTokenParser.java:69) at org.apache.ibatis.builder.SqlSourceBuilder.parse (SqlSourceBuilder.java:45) at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql (DynamicSqlSource.java:44) at org.apache.ibatis.mapping.MappedStatement.getBoundSql (MappedStatement.java:292) at org.apache.ibatis.executor.CachingExecutor.query (CachingExecutor.java:81) 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.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) 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:434) at com.sun.proxy.$Proxy57.selectList (Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectList (SqlSessionTemplate.java:231)
<select id="getById" parameterType="map" resultType="Report"> select * from test where orderid in <foreach collection="idlist" item="item" index="index" open="(" separator="," close=")"> #{item} </foreach> </select>
怎么找都没找到原因,最后发现这个sql之所以报错并不是这个sql写错了,而是传入的参数报错了,我认为参数是这个样子的:
{ "name":"张三", "idlsit":{1,2,3} }
最后发现,参数是这个样子的的:
{ "name":"张三", "idlsit":{Report对象,Report对象,Report对象} }
看到这里可能会觉得怎么可能出现这种问题,编译都不会通过,但是通过特殊的情况确实产生了,我的代码如下:
List<String> idList = reportDao.getIdList(start, end); if (null != idList && idList.size() >= 1) { result = orderReportDao.getById(idList, start); }
sql:
<select id="getIdList" parameterType="map" resultType="Report">//这个返回值类型错了 select id from test_id </select> <select id="getById" parameterType="map" resultType="Report"> select * from test where orderid in <foreach collection="idlist" item="item" index="index" open="(" separator="," close=")"> #{item} </foreach> </select>
实际上在执行过程中getIdList的返回类型错了,但是没有报错误,返回值List < String > idList实际上是List < Report > idList,这竟然没有报错,可能反射有关。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- v8 cve-2019-5791:模块耦合导致的类型混淆
- Unchecked Conversion 导致的 Java 方法返回类型变更
- MySQL对JSON类型UTF-8编码导致中文乱码探讨
- Flash Player类型混淆严重漏洞,成功利用可能导致任意代码执行(CVE-2018-15981)
- 类初始化导致死锁
- 组合漏洞导致的账号劫持
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Google's PageRank and Beyond
Amy N. Langville、Carl D. Meyer / Princeton University Press / 2006-7-23 / USD 57.50
Why doesn't your home page appear on the first page of search results, even when you query your own name? How do other web pages always appear at the top? What creates these powerful rankings? And how......一起来看看 《Google's PageRank and Beyond》 这本书的介绍吧!