您的位置:首页 > 其它

MyBatis(3.2.3) - Multiple results as a map

2016-03-01 17:05 183 查看
If we have a mapped statement that returns multiple rows and we want the results in a HashMap with some property value as the key and the resulting object as the value, we can use sqlSession.selectMap() as follows:

<select id=" findAllStudents" resultMap="StudentResult">
select * from Students
</select>

Map<Integer, Student> studentMap = sqlSession.selectMap("com.mybatis3.mappers.StudentMapper.findAllStudents", "studId");


Here studentMap will contain studId values as keys and Student objects as values.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: