不能直接遍历map么?
我看了下网上的,只能使用嵌套的方式
声明一个value为map的map,然后在foreach的时候
collection="key"
比如
public static void main(String[] args) {
MybatisDao dao = new MybatisDao();
Map<String,Map<String,Integer>> map = new HashMap<>();
Map<String,Integer> map1 = new HashMap<>();
map1.put("aaa",1);
map1.put("bbb",2);
map.put("first",map1);
List<Message> lis = dao.queryMessageByMap(map);
}
public List<Message> queryMessageByMap(Map<String,Map<String,Integer>> params){
DBAccess dbAccess = new DBAccess();
SqlSession sqlSession = null;
List<Message> messageList = null;
try {
sqlSession = dbAccess.getSqlSession();
messageList = sqlSession.selectList("Message.selectMap",params);
} catch (IOException e) {
e.printStackTrace();
}
return messageList;
}对应的mapper中的sql:
<select id="selectMap" parameterType="map" resultType="com.imooc.bean.Message">
select ID,COMMAND,DESCRIPTION,CONTENT from message WHERE id IN
<foreach collection="first" index="index" item="value" open="(" close=")" separator=",">
#{value}
</foreach>
</select>有能直接就遍历的方法么?
#{index.id}