mybatis的mapper.xml使用循环语句

来源:互联网 发布:淘宝虚拟物品退款 编辑:程序博客网 时间:2024/06/09 22:27

1.mapper.java,传的参数是map

List<实体类> getList(Map<String,Object> paraMap);

2.mapper.xml

<select id="getList" parameterType="java.util.Map" resultMap="BaseResultMap">  select * from table where   <if test="a!= null">      a = #{a,jdbcType=VARCHAR}  </if>  <if test="list!= null">    and id in    <foreach item="item" index="index" collection="list" open="(" close=")" separator=",">     #{item}    </foreach>  </if></select>

3.参数,数组,list都行

Map<String,Object> map = new HashMap<String, Object>();map.put("a","参数");map.put("list",数组、List都行)List<实体类> list = mapper.getList(map);
原创粉丝点击