【笔记】对遍历List,对List里的对象做删除操作

本文介绍了一种使用MyBatis将表格中某一列的多行数据转换为单行数据的方法,并通过SQL实现去除重复项。此外,还展示了如何根据查询条件筛选并组合特定的数据行。
// 对某一列做多行转一行,并去除重复的行
<select id="selectCodeStr" parameterType="com.xxx.ResourceIndex" resultType="String">
       with tmp as (select distinct cate_codes from cbp_resource_index 
        <where>
            <if test="title != null and title != ''">
                or title LIKE '%${title}%'
            </if>
            <if test="keywords != null and keywords != ''">
                or keywords LIKE '%${keywords}%'
            </if>
            <if test="author != null and author != ''">
                or author LIKE '%${author}%'
            </if>
            <if test="cateCodes != null and cateCodes != ''">
                AND cate_codes LIKE '%${cateCodes}%'
            </if>
            <if test="departId != null and departId != ''">
                AND depart_id = #{departId}
            </if>
        </where> 
        )
       SELECT ''+cate_codes+'' FROM tmp FOR XML PATH('')
    </select>
/* 遍历取出符合的分类 */
        // 存储符合的分类
        String str = resourceIndexMapper.selectCodeStr(resourceIndex);

        ListIterator<Category> it = cateList.listIterator();
        while(it.hasNext()){
            Category cate = it.next();

            if(!str.contains(cate.getCode())){
                it.remove();
            }else{
                Iterator<Category> itTemp = cate.getChildrenList().iterator();
                while(itTemp.hasNext()){
                    if(!str.contains(itTemp.next().getCode())){
                        itTemp.remove();
                    }
                }
            }
        }
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值