首页 > 其他 > 详细

MyBatis(3.2.3) - Multiple results as a map

时间:2016-03-01 17:24:01      阅读:108      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!