sql精简如下:
select CHECKLIST_ID
from A WHERE CHECKLIST_ID in (1,2)) order by DT_UPDATE desc
其中CHECKLIST_ID pojo层为LONG型,mybatis resultMap映射如下
<id column="CHECKLIST_ID" jdbcType="DECIMAL" property="checklistId"/>
Example_Where_Clause如下
<when test="criterion.listValue">
and ${criterion.condition} <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> #{listItem} </foreach> </when>
这样会报错
org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: java.lang.reflect.UndeclaredThrowableException
The error may exist in com/lianpay/risk/check/sqlmap/RiskEventChecklistMapper.xml
当 #{listItem}改成 ${listItem} 就没有什么问题,即:
<when test="criterion.listValue"> and ${criterion.condition} <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> ${listItem} </foreach> </when>
求解,之前一直那么用的,难道和LONG型有关??
在mybatis中,#{} 相当于是JDBC的preparestatement,是预编译的,${}不是预编译的,会有SQL注入的风险,其实你可以看看SQL打印出的log,然后run一下这些SQL,看看哪种是正确的。