入参为List的写法:
Mapper 文件的写法:
<select id="queryParamList" resultType="map" parameterType="java.util.List">
select id from static
where id in
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
其中<foreach>这个标签是用来循环传入的集合的,collection="list"这个参数中有list,map两种,还有就是自定义的参数,item="item"这个参数可以自定义,用来循环集合里面的值,这个参数的取名要和下面#()这个里面的取名一致。
parameterType="java.util.List"这个传入的参数类型不能简写成List(其中只有基本数据类型可以简写)。
ps:当然,如果用in来查询的,可以用一个string来写,如上图列子:将id手动拼接成一个string传入。参照sql语句的规则。
入参为Map的写法:
<selectid="findTeacherByPage"resultMap="supervisorResultMap"
parameterType="java.util.Map">
select * from teacher
where name= #{name}
limit #{start},#{limit}
</select>
注:map中的key值就是name,start,limit。