sql foreach记录

本文介绍了一个使用MyBatis进行复杂SQL查询及批量插入操作的例子。其中包括通过站码获取系统用户的查询过程,以及批量插入合租房源卧室信息的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@RequestMapping("/test")
    public void springTest() {
        System.out.println("**************");
        List<String> list = new ArrayList();
        list.add("sys_manage");
        list.add("pledge");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("stationCode", list);
        List ss = TemplateUserDao.getSysUsersByStationCode(map);
        System.out.println(ss);

    }

<select id="getSysUsersByStationCode" parameterType="java.util.Map"
        resultType="com.iqb.eatep.house.rabbit.mq.data.bean.SysUser">
        SELECT
        DISTINCT
        u.USER_CODE AS userCode,
        u.USER_NAME AS userName,
        u.REAL_NAME as realName,
        u.USER_EMAIL as userEmail,
        u.STATUS as status,
        u.USER_PHONE as userPhone,
        u.STATION_CODE as stationCode
        FROM
        iqb_sys_user u
        WHERE
        <if test="stationCode!=null and stationCode!=''">
        <foreach item="item" index="index" collection="stationCode" open="(" separator="or" close=")">
                u.STATION_CODE LIKE CONCAT('%', #{item,jdbcType=VARCHAR}, '%')
        </foreach>    
        </if>
    </select>

 

 

<select id="getSysUsers" parameterType="java.util.Map"
        resultType="com.iqb.eatep.house.rabbit.mq.data.bean.SysUser">
        SELECT
        u.USER_CODE AS userCode,
        u.USER_NAME AS userName,
        u.REAL_NAME as realName,
        u.USER_EMAIL as userEmail,
        u.STATUS as status,
        u.USER_PHONE as userPhone,
        u.STATION_CODE as stationCode
        FROM
        iqb_sys_user u
        WHERE
        <if test="users!=null and users!=''">
            u.USER_CODE in
            <foreach item="item" index="index" collection="users" open="("
                separator="," close=")">
                #{item}
            </foreach>
        </if>
    </select>

 

    <!-- 合租房源卧室分别记录 -->
    <insert id="insertRentUserList" parameterType="java.util.List">
        insert into ete_rent_user_info (RENT_HOUSE_ID,RENT_TYPE,ROOM_LEVEL,ROOM_ACREAGE,RENT_TIME,RENT_STATUS)
        values
        <foreach collection="list"  item="item"  index="index" separator=",">
        (#{item.rentHouseId},#{item.rentType},#{item.roomLevel},#{item.roomAcreage},UNIX_TIMESTAMP(),#{item.rentStatus})
        </foreach>
    </insert>

转载于:https://my.oschina.net/u/3229047/blog/865218

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值