mybatis foreach 示例

 public List<PreloadData> getDatas(Map<String, Object> params);

 <resultMap id="preloadData" type="com.chinacache.entity.PreloadData">
        <result column="time_num" property="timeNum" />
        <result column="count" property="count" />
        <result column="filesize" property="fileSize" />
        <result column="day" property="day" />
    </resultMap>
    <select id="getDatas" resultMap="preloadData">
        select SUM(count) as count,SUM(FILESIZE) as FILESIZE,to_char(day,'yyyymmdd') as day,time_num from
        BANDWIDTH_PRELOAD
        <where>
            <foreach collection="ids" index="index" item="item" open="(" separator="or" close=") and">
                CHANNEL_ID=#{item}
            </foreach>
           <![CDATA[ day>=to_date(#{startDay},'yyyymmdd') and day<=to_date(#{endDay},'yyyymmdd')]]>
        </where>
        GROUP BY day,time_num order by day,time_num
    </select>

  Map<String, Object> params = new HashMap<String, Object>();
        params.put("ids", channelIDs);
        params.put("startDay", sdf.format(startTime));
        params.put("endDay", sdf.format(endTime));
        return this.preloadMapper.getDatas(params);

你可能感兴趣的:(mybatis)