mybatis批量插入
传统插入方式为:
<insert id="create" parameterType="FcHydrantDetailEntity"> insert into fc_hydrant_detail (id, hydrantId, checkDate, checkUser) values(#{id}, #{hydrantId}, #{checkDate}) </insert>
dao层传入一个实体类,mapper里插入一条数据。
批量插入:
<insert id="createList" parameterType="List"> insert into fc_hydrant_detail (id, hydrantId, checkDate) values <foreach collection ="list" item="item" index= "index" separator =","> (#{item.id}, #{item.hydrantId}, #{item.checkDate}) </foreach> </insert>
dao层传入一个list<Entity>,mapper里将parameterType改为"List",使用foreach遍历list,foreach中,item表示集合中每一个元素进行迭代时的别名,separator表示在每次进行迭代之间以什么符号作为分隔符,collection属性为传入的类型,传入为list时,collection属性值为list,传入为数组时,collection属性值为Array
相关推荐
技术驱动人生 2020-03-24
xiuyangsong 2020-02-23
cuterabbitbaby 2020-01-09
zhiyuan0 2020-01-04
技术驱动人生 2019-12-22
Justagreenonion 2019-12-07
dongxurr 2019-10-20
渐渐老去 2015-12-17
cuterabbitbaby 2015-01-30
indigosummer 2014-12-18
渐渐老去 2014-04-30
lonyness 2015-12-22
mrsuddenflash 2014-04-04
zhaojp0 2011-04-30
Nishinoshou 2019-06-21
周嘉笙 2018-06-21
rocky00 2009-08-31
CLASSICHUO 2009-06-04
尘封飞扬 2019-04-01