cause
The following error is reported when using mybatis dynamic SQL to traverse conditions:
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>
I can’t find the reason why I didn’t find it. At last, I found that the reason why the SQL reported an error is not that the SQL was written wrong, but that the parameter passed in was reported wrong. I think the parameter looks like this:
{
"Name": "Zhang San",
"idlsit":{1,2,3}
}
Finally, it is found that the parameters look like this:
{
"Name": "Zhang San",
"Idlsit": {report object, report object, report object}
}
See how this problem may occur here. Compilation will not pass, but it does occur through special circumstances. My code is as follows:
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" > // the return value type is wrong
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>
In fact, the return type of getidlist is wrong during execution, but there is no error reported. The return value list < string > idlist is actually list < report > idlist, which actually has no error reported. It may be related to reflection.