int updateByList(List list)
Mappe层
批量修改
<update id="updateByList" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" separator="">
update jt_fin_repayment_plan
<set >
erestTotal != null" >
ORG_INTEREST_TOTAL = #{item.orgInterestTotal},
</if>
<if test="item.delFlag != null" >
DEL_FLAG = #{item.delFlag},
</if>
<if test="item.state != null" >
STATE = #{item.state},
</if>
<if test="item.createBy != null" >
CREATE_BY = #{item.createBy},
</if>
<if test="item.createTime != null" >
CREATE_TIME = #{item.createTime},
</if>
<if test="item.updateBy != null" >
UPDATE_BY = #{item.updateBy},
</if>
UPDATE_TIME = #{NOW(),
</set>
where REPAYMENT_ID = #{item.repaymentId}
</foreach>
</update>
----------------------------------------------------------------------------------------------------------
dao层
//批量添加
int addList(List list)
Map层
批量添加
<insert id="addList" parameterType="java.util.List">
insert into jt_fin_adjust_rates_project_history (
ID,ADJUST_RATES_ID,PROJECT_ID,START_WHOLE,
END_WHOLE,START_WITHOUT,END_WITHOUT,PROJECT_DATE,
KEEP,AUDIT_FLAG,STATUS,REMARK,DEL_FLAG,
CREATE_BY,CREATE_TIME,UPDATE_TIME,UPDATE_BY
)
values
<foreach collection="list" separator="," item="item" index="index">
((select UUID()), #{item.adjustRatesId},#{item.projectId},#{item.startWhole},
#{item.endWhole},#{item.startWithout},#{item.endWithout},#{item.projectDate},
#{item.keep},#{item.auditFlag},#{item.status},#{item.remark},#{item.delFlag},
#{item.createBy},sysdate(), #{item.updateTime}, #{item.updateBy})
</foreach>
</insert>
注意:我的id VARCHAR类型 主键 不能递增 在这里我用的是UUID生成的
原本,想写一个批量添加,回显id但是没实现就不写了,有大佬可以补充一下
这个要执行一下,调用一下这个方法才能确定有没有问题关于mybatis批量插入的问题,建议你查看一下
http://limingnihao.iteye.com/blog/781671
mybatis的详细教程,
批量增加<insert id="batchSaveUser">
insert into t_user (user_name,sex) values
<!-- 动态SQL之foreach的用法 -->
<!-- collection="users" 用于指定循环集合的名称,如果接口中并未指定参数别名,那么默认就是list
item="u" 用于指定每次循环后的对象的别名
separator="," 用于指定每次循环后之间的分割符-->
<foreach collection="users" item="u" separator=",">
(#{u.userName},#{u.sex})
</foreach>
</insert>
批量删除
<delete id="batchDeleteUser">
delete from t_user where id in (
<foreach collection="ids" item="id" separator=",">
#{id}
</foreach>
)
</delete>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)