1. 程式人生 > >MyBatis-sqlMapper傳入List型別引數,返回List型別引數。

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 and #{0}.size() != 0">
				channel_id in
				<foreach item="tempId" collection="list" open="(" separator="," close=")">
    	                #{tempId}
        	    </foreach>
			</if>
         
		</where>  
		
	
	</select>

resultType設定成String,myBatis會自動將結果轉成List集合。