Mybatis遍历修改和添加

https://note.youdao.com/share/?id=056b64b482370c18ccfb5f7f8dda3687&type=note#/

mybaits传参问题(传入list),批量插入

在这个批量插入的语句中,collection="list" 这是死的,不能更改的,不管在DAO传什么参数,只要是list类型的都可以用,item="item"是遍历这个list的一个引用对像。

<insert id="insertBatch" >

insert into student ( <include refid="Base_Column_List" /> )

values

<foreach collection="list" item="item" index="index" separator=",">

(null,#{item.name},#{item.sex},#{item.address},#{item.telephone},#{item.tId})

foreach>

insert>

<include refid="Base_Column_List" />

这句话的意思是在那个xml文件中会有一个以Base_Column_List为ID的SQL语句

 

update jc_abnormal_detail

when id = #{i.abnormityId} then #{i.channelId}

when id = #{i.abnormityId} then DATE_FORMAT(#{i.endTime},'%Y-%m-%d %H:%i:%s')

在以上的批量更新时,需要注意的是:1.when是作为更新条件的;2.then是传进来对像中的某一个值 把对像的值赋给 等于case的值 。

你可能感兴趣的:(Java开发)