mybatis批量保存,修改
<insert id="saveBatchForList" parameterType="java.util.List"> insert into T_PRICE_PPI_BASEWEIGHT (BASEYEAR,ORGCODE,ORGNAME, BASECODE, BASENAME,WEIGHT,DATA_TYPE,STARTTIME,CREATOR,CREATETIME,AREACODE,AREANAME,GROUP_ITEM_TYPE,AMOUNT,STATUS,BASEWEIGHT_VERSION) values <foreach collection="list" item="item" index="index" separator=","> (#{item.baseyear},#{item.orgcode},#{item.orgname},#{item.basecode},#{item.basename},#{item.weight},#{item.dataType},#{item.starttime},#{item.creator}, #{item.createtime},#{item.areacode},#{item.areaname},#{item.groupItemType},#{item.amount},#{item.status},#{item.baseweightVersion}) </foreach> </insert>
public static <T> List<List<T>> getBeginEnd(List list, Class clazz) { List data = new ArrayList<>(); if (list == null || list.size() == 0) return data; int total = list.size(); int pagesize = 800; int totalPages = (int) (total % pagesize == 0 ? total / pagesize : (total / pagesize) + 1); for (int i = 1; i <= totalPages; i++) { int start = (i - 1) * pagesize; int end = (i * pagesize) > total ? total : (i * pagesize); data.add(JSON.parseArray(JSON.toJSONString(list.subList(start, end)), clazz)); } return data; }
xml 循环条件
<update id="updateAuditStatus" parameterType="com.thtf.zwdsj.gongjia.param.sql.WeightVersionSql"> update T_PRICE_PPI_BASEWEIGHT set STATUS = #{weightVersionVo.status} where BASEWEIGHT_VERSION = #{weightVersionVo.baseweightVersion} and DATA_TYPE = #{weightVersionVo.dataType} and BASECODE in <foreach collection=" weightVersionVo.basecode " index="index" item="item" open="(" separator="," close=")"> #{item} </foreach> <choose> <when test="weightVersionVo.areacode !=null and weightVersionVo.areacode !=''"> and AREACODE like concat(#{weightVersionVo.areacode},'%') and areacode <> #{weightVersionVo.areacode} </when> <otherwise> and AREACODE like '__0000%'; </otherwise> </choose> </update>
浙公网安备 33010602011771号