MyBatis-sqlMapper传入List类型参数,返回List类型参数。

Mapper.java

public interface StorageMapper extends BaseMapper<Storage> {

    List<Integer> getStorageIdByChannelId(List<Integer> channelIds);

}

mapper.xml

<select id="getStorageIdByChannelId" resultType="java.lang.String">
        select 
            storage_id
        from 
        res_storage 
        <where>
            <if test="#{0} != null">
                channel_id in
                <foreach item="tempId" collection="list" open="(" separator="," close=")">
                        #{tempId}
                </foreach>
            </if>

        </where>  


    </select>

resultType设置成String,myBatis会自动将结果转成List集合。

猜你喜欢

转载自blog.csdn.net/u013719012/article/details/77335521