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.