Java_12 批量插入数据、mapper分页模糊查

批量插入数据

// 批量插入
if (!voteOwner1.isEmpty()) {
    List<VoteOwner> voteOwners2 = new ArrayList<>();
    //vo1为待插入数据
    for (int i = 0; i < voteOwner1.size(); i++) {
        //把vo1的数据加进新的列表vo2,若vo2的大小>=200或者vo1为最后一条数据,执行插入操作
        voteOwners2.add(voteOwner1.get(i));
        if (voteOwners2.size() >= 200 || i == voteOwner1.size() - 1) {
            Map<String, Object> m = new HashMap<>();
            m.put("list", voteOwners2);
            try {
                //每200条数据添加一次,添加完清空vo2
                this.voteOwnerService.addList(m);
                voteOwners2.clear();
            } catch (Exception e) {
                return ResultMap.error(e.getMessage());
            }
        }
    }
}
//allowMultiQueries=true代表可以批量更新
spring.db2.datasource.url=jdbc:mysql://url/cs?useUnicode=true&characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true

mapper分页模糊查

<select id="queryPageByLimit" resultMap="LogMap">
    select
    UnitGuid, OwnerName, OwnerGuid, Mobile, CreateDate, Remark, Ip, TenantGuid, LogType, Url, Duration, Description, Type, PropertyAccountId
    from sys_log
    <trim prefix="where" prefixOverrides="and">
        <if test="unitGuid != null and unitGuid != ''">
            and UnitGuid = #{unitGuid}
        </if>
        <if test="keyWord != null and keyWord != ''">
            and OwnerName like concat('%',#{keyWord},'%') or Mobile like concat('%',#{keyWord},'%')
        </if>
    </trim>
    ORDER BY CreateDate DESC
    limit #{offset}, #{pageSize}
</select>