首先看mybatis的查询语句
parameterType是传入的参数类型,当传入是基本数据类型时候:
<select id="findStudentById" parameterType="int" resultMap="studentList">
select * from t_student where id =#{_parameter}
</select>
当传入是集合时候:
java代码:
public List<Student> findStudentById(int[] i)
对应得xml:
<select id="findStudentById" parameterType="int[]" resultMap="studentList">
select * from t_student where id in
<foreach collection="array" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
当传入是list的时候:
java代码:
public List<Student> findStudentById(List<Integer> i);
对应得xml:<select id="findStudentById" parameterType="list" resultMap="studentList">
select * from t_student where id in
<span style="white-space:pre"> </span><foreach collection="list" index="index" item="item" open="(" separator="," close=")">
<span style="white-space:pre"> </span>#{item}
</foreach>
</select>
当传入是map的时候:
public List<Student> findStudentById(Map<String, List<Integer>> map);</span>
对应得xml:
<select id="findStudentById" parameterType="map" resultMap="studentList">
select * from t_student where id in
<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>