MyBatis(3.2.3) - Multiple results as a map
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.
以上是关于MyBatis(3.2.3) - Multiple results as a map的主要内容,如果未能解决你的问题,请参考以下文章
MyBatis3-传递多个参数(Multiple Parameters)