mirror of https://gitee.com/makejava/EasyCode.git
default新增两个超实用方法:
insertBatch 批量插入(MyBatis原生foreach方法) insertOrUpdateBatch 批量插入或按主键更新(MyBatis原生foreach方法)
This commit is contained in:
parent
2f845a5558
commit
29db8621a7
|
@ -57,6 +57,22 @@ public interface $!{tableName} {
|
|||
*/
|
||||
int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
|
||||
|
||||
/**
|
||||
* 批量新增数据(MyBatis原生foreach方法)
|
||||
*
|
||||
* @param List<$!{tableInfo.name}> 实例对象列表
|
||||
* @return 影响行数
|
||||
*/
|
||||
int insertBatch(@Param("entities") List<$!{tableInfo.name}> entities);
|
||||
|
||||
/**
|
||||
* 批量新增或按主键更新数据(MyBatis原生foreach方法)
|
||||
*
|
||||
* @param List<$!{tableInfo.name}> 实例对象列表
|
||||
* @return 影响行数
|
||||
*/
|
||||
int insertOrUpdateBatch(@Param("entities") List<$!{tableInfo.name}> entities);
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
|
@ -73,4 +89,4 @@ public interface $!{tableName} {
|
|||
*/
|
||||
int deleteById($!pk.shortType $!pk.name);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,24 @@ $!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))
|
|||
values (#foreach($column in $tableInfo.otherColumn)#{$!{column.name}}#if($velocityHasNext), #end#end)
|
||||
</insert>
|
||||
|
||||
<insert id="insertBatch" keyProperty="$!pk.name" useGeneratedKeys="true">
|
||||
insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
|
||||
values
|
||||
<foreach collection="entities" item="entity" separator=",">
|
||||
(#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<insert id="insertOrUpdateBatch" keyProperty="$!pk.name" useGeneratedKeys="true">
|
||||
insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
|
||||
values
|
||||
<foreach collection="entities" item="entity" separator=",">
|
||||
(#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)
|
||||
</foreach>
|
||||
on duplicate key update
|
||||
#foreach($column in $tableInfo.otherColumn)$!column.obj.name = values($!column.obj.name) #if($velocityHasNext), #end#end
|
||||
</insert>
|
||||
|
||||
<!--通过主键修改数据-->
|
||||
<update id="update">
|
||||
update $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
|
||||
|
@ -77,4 +95,4 @@ $!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))
|
|||
delete from $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue