Mybatis因为会与数据库交互,所以经常会有返回map集合的场景,那一般mybatis返回map集合的格式是什么呢?下面小编就用一些实例与你分享分享吧。
例1:返回key不定:返回key为学员id,value集合为学员信息
javaDao层:/**
* 获取学员分类 以id为key, StudentType对象为value
*
* @return
*/
@Override
public Map getStudentTypeMap()
{
return this.sqlSession.selectMap("StudentTypeMapper.getStudentTypeMap", "id");
}
Mapper配置文件:
select
from edu_student_type
例2:返回指定map中的具体key
javaDao层:指定key为userPaperpublic Map getExamPaperRecordMaxScoreByUserIds(String userIds)
{
return sqlSession.selectMap("PaperRecordMapper.getExamPaperRecordMaxScoreByUserIds", userIds, "userPaper");
}
Mapper配置文件:
SELECT * FROM (
SELECT CONCAT_WS('_', cus_id, parent_id) AS userPaper,
exam_exampaper_record.id,
exam_exampaper_record.user_score AS userScore,
exam_exampaper_record.cus_id AS cusId,
exam_exampaper_record.parent_id AS parentId,
exam_exampaper_record.add_time AS addTime
FROM exam_exampaper_record
WHERE exam_exampaper_record.status = 0
AND !ISNULL(parent_id)
AND cus_id IN (${value})
ORDER BY user_score DESC LIMIT 100000000
)AS a
GROUP BY a.cusId, a.parentId
以上就是今天的所有内容了,更多相关mybatis常见问题请持续关注本网站了解详情吧。
推荐阅读: