mybatis连表查询返回map类型
程序员文章站
2022-07-01 07:54:24
...
- mapper.xml
<select id="test1" resultType="Map">
select t.tid,t.tname,c.cname from teacher t join course c on t.tid=c.tid
</select>
- mapper.java
//1.查询老师信息和其课程信息
List<Map<String,Object>> test1();
- Test
@Test
public void test1(){
SqlSession sqlSession = MybatisUtils.getSqlSession();
TestMapper mapper = sqlSession.getMapper(TestMapper.class);
List<Map<String, Object>> maps = mapper.test1();
for(Map<String,Object> map:maps){
Set<String> set=map.keySet();
Iterator<String> it=set.iterator();
while(it.hasNext()){
Object key=it.next();
Object value=map.get(key);
System.out.println(value);
}
}
sqlSession.close();
}
参考
上一篇: Java8中forEach语句循环一个List和Map
下一篇: python定义具名元组实例操作