MyBatis Cause: java.sql.SQLException: Operand should contain 1 column(s) 异常处理

来源:互联网 发布:华东师范大学vnp软件 编辑:程序博客网 时间:2024/06/03 18:22

用mybatis foreach出现异常Operand should contain 1 column(s)

    <select id="selectByCreditIdList" resultMap="BaseResultMap">        SELECT * FROM table        WHERE id IN (                    <foreach collection="creditIdList" item="cid" index="index" open="(" close=")" separator=",">                        #{cid}                    </foreach>                    )    </select>   

暴出的异常如下。

Error querying database.  Cause: java.sql.SQLException: Operand should contain 1 column(s)### The error may exist in com/fengdai/finance/dao/CreditBillCycleDao.xml### The error may involve defaultParameterMap### The error occurred while setting parameters### SQL: SELECT * FROM credit_bill_cycle   WHERE   (         id IN (       (         ?       ,        ?       )     )   )### Cause: java.sql.SQLException: Operand should contain 1 column(s)

发现生成IN 后跟随的列表是一个( ? , ? ) ,因此产生Operand should contain 1 column(s)异常。删除MyBatis sql映射文件中的外围括号,问题解决。

(  <-删除                    <foreach collection="creditIdList" item="cid" index="index" open="(" close=")" separator=",">                        #{cid}                    </foreach>) <- 删除
0 1
原创粉丝点击