mybatis的mapper.xml使用迴圈語句
阿新 • • 發佈:2018-11-05
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);