mybatis XML中 遍历map写法


   <select id="selectMapTest" parameterType="java.util.HashMap" resultMap="BaseResultMap">
        <foreach collection="map1" index="key" item="ent" separator="union">
            SELECT *
            FROM User
            where username=#{key}
            and userpass in
            <foreach collection="ent" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
        </foreach>

    </select>

 对应的mapper中是:

//map测试
List<User> selectMapTest(@Param("map1") Map<String,List<Integer>> ma1);


注意:foreach标签中的index就是map的key值


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM