<select id="findUserByIds" parameterType="com.pojo.QueryVo" resultType="com.pojo.User"> SELECT * from USER <where> <if test="ids !=null"> <!-- foreach:循環傳入的集合參數 collection:傳入的集合的變量名稱 item:每次循環將循環出的數據放入這個變量中 open循環開始拼接的字符串 separator:循環中拼接的分隔符 --> <foreach collection="ids" item="id" open="id in(" close=")" separator=","> #{id} </foreach> </if> </where> </select>
