MyBatis(3.2.3) - Multiple results as a map

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.

posted on 2016-03-01 17:05  huey2672  阅读(514)  评论(0)    收藏  举报