Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MyBatis - How to write <if> statement under <foreach>?

I loop a collection, and only when the item of the collection is not null, then it will be inserted into the DB, the snippet code like that:

<foreach collection="ids" item="id" separator=",">
    <if test="id!= null">
       (#{id})
    </if>
</foreach>

the statement run failed, it said "Parameter 'id' not found.", the I change the statement :

<if test="#{id}!= null">

It failed also, so how can I write the statement?

like image 907
Rocky Hu Avatar asked Oct 19 '22 05:10

Rocky Hu


1 Answers

Update the version from 3.2.8 to 3.3.0, it will be fixed.

like image 158
Rocky Hu Avatar answered Oct 29 '22 14:10

Rocky Hu