欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

mysql 实现批量添加和更新功能

最编程 2024-04-02 17:38:26
...

//mapper.xml文件配置

单独添加
 <!-- Integer addbCompany(bCompany bc);注册网点 -->
 <insert id="addbCompany" parameterType="com.select.wuliu.entity.bCompany"
 useGeneratedKeys="true" keyProperty="id">
insert into company_address
(branchName,address,phone,telephone,companyId,contact,
qz,isDel,longitude,dimensions,branchprovince,branchcity,brancharea,
branchrelation,intro,culture

)
values
(#{branchName},#{address},#{phone},#{telephone},#{companyId},#{contact},
#{qz},#{isDel},#{longitude},#{dimensions},#{branchprovince},#{branchcity},#{brancharea},
#{branchrelation},#{intro},#{culture}
)
</insert>
实现批量添加
<!-- 批量添加线路 Integer addPathers(List<Pather> pa); -->
<insert id ="addPathers" parameterType="java.util.List" >
  insert into line
  (sta,end,wl_id,qz,del_flag,type,tui,direct

)
  values
   <foreach collection ="list" item="Pather" index= "index" separator =",">
       (
       #{Pather.sta}, #{Pather.end},
       #{Pather.wlId},
       #{Pather.qz},
       #{Pather.delFlag}, #{Pather.type}
       , #{Pather.tui}, #{Pather.direct}
       
       )
   </foreach > </insert >

批量更新

<update id="setdelPathers" parameterType="java.util.List">
UPDATE 
	line
SET
	del_flag= #{del_flag}
WHERE id in
	 <foreach collection="list" index="index" item="Pather" 
    separator="," open="(" close=")">
    #{Pather.id}
</foreach>

 </update>

推荐阅读