mybatis的mapper.xml使用循环语句

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);

猜你喜欢

转载自blog.csdn.net/qq_30059235/article/details/72473942