码迷,mamicode.com
首页 > 其他好文 > 详细

MyBatis(3.2.3) - Multiple results as a map

时间:2016-03-01 17:26:58      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

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.

MyBatis(3.2.3) - Multiple results as a map

标签:

原文地址:http://www.cnblogs.com/huey/p/5231724.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!