LONG型IN操作时mybatis 出现UndeclaredThrowableException异常

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型有关??
            
阅读 3.2k
1 个回答

在mybatis中,#{} 相当于是JDBC的preparestatement,是预编译的,${}不是预编译的,会有SQL注入的风险,其实你可以看看SQL打印出的log,然后run一下这些SQL,看看哪种是正确的。

select CHECKLIST_ID
 from A
     WHERE CHECKLIST_ID in
            (1,2))
     order by DT_UPDATE desc
select CHECKLIST_ID
 from A
     WHERE CHECKLIST_ID in
            ('1','2'))
     order by DT_UPDATE desc
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题