您的位置:首页 > 其它

mybatis中传入一个List或Map集合作为查询条件的参数

2017-11-30 10:29 731 查看
入参为List的写法:
Mapper 文件的写法:
<select id="queryParamList" resultType="map" parameterType="java.util.List">select id from staticwhere 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。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mybatis mvc ssm