当调用接口:
public List<Message> getMessage(String company, List<Integer> types);
userMapper.xml的书写应该为:
<select id="getMessage" resultType="Message">
SELECT * FROM op_message m where not EXISTS(SELECT ID FROM
op_del_message d where d.id = m.id and d.COMPANY=#{param1}) and
m.COMPANY=#{param1}
<if test="types!=null">
<foreach collection="param2" item="type" separator="," open="and type in ("
close=")">
#{type}
</foreach>
</if>
</select>
mybatis会自动将多个不同类型的参数改成param1,param2...
或者采用Mybatis的Annotation(@Param):
public List<Message> getMessage(@Param("company") String company, @Param("types") List<Integer> types);
<select id="getMessage" resultType="Message">
SELECT * FROM op_message m where not EXISTS(SELECT ID FROM
op_del_message d where d.id = m.id and d.COMPANY=#{company}) and
m.COMPANY=#{company}
<if test="types!=null">
<foreach collection="types" item="type" separator="," open="and type in ("
close=")">
#{type}
</foreach>
</if>
</select>