mybatis 查询数据库,返回map集合
2018-11-13 14:45
609 查看
1.不指定返回的key:返回以学员id为key,学员信息为value的集合
java代码(dao实现层)
[code]/** * 获取学员分类 以id为key, StudentType对象为value * * @return */ @Override public Map<Long, StudentType> getStudentTypeMap() { return this.sqlSession.selectMap("StudentTypeMapper.getStudentTypeMap","id"); }
mapper文件
[code]<!--获取学员分类 以id为key, StudentType对象为value--> <select id="getStudentTypeMap" resultType="StudentType"> select <include refid="edu_student_type_columns"/> from edu_student_type </select>
2.指定返回的map中的具体的key
dao层:指定key为userPaper
[code] public Map<String, PaperRecordDto> getExamPaperRecordMaxScoreByUserIds(String userIds) { return sqlSession.selectMap("PaperRecordMapper.getExamPaperRecordMaxScoreByUserIds",userIds,"userPaper"); }
阅读更多mapper文件
[code] <!--获取用户每张试卷的最高成绩的考试信息 以 userId_parentId 作为key, PaperRecord对象作为value 此处内层查询 在mysql5.7后 order by 字段后必须加 limit 否则外层group by 的结果仍未排序--> <select id="getExamPaperRecordMaxScoreByUserIds" parameterType="String" resultType="PaperRecordDto"> 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 </select>
相关文章推荐
- 好947 Mybatis 配置resultMap 带参数查询Map 注意selectOne数据库返回结果一条数据库 否则会报错
- mybatis中传入一个List或Map集合作为查询条件的参数
- mybatis多表查询返回map类型
- mybatis group by查询返回map类型
- Ibatis/mybatis中,查询SQL参数和返回都是Map的情况
- jdbc查询数据库返回实体对象集合
- Spring boot + MyBatis 查询返回Map时设置值为null的字段也在结果集中
- springboot+mybatis MyBatis查询返回Map时设置值为null的字段没有在结果集中
- MyBatis项目查询数据库Could not find result map java.lang.String
- 数据库查询返回List<Map<String, Object>>
- mybatis-查询(resultMap,关联集合)-15
- MyBatis查询返回Map类型数据
- mybatis学习之查询结果返回List以及Map
- Mybatis 连表查询,返回结果封装为Map
- Mybatis查询数据库空字段不返回
- springMVC+mybatis查询数据,返回resultType=”map”时,如果数据为空的字段,则该字段省略不显示的解决方案
- Mybatis 查询结果返回 Map
- Mybatis对有可能返回empty set的数据库查询结果进行操作
- Mybatis查询返回map数据
- mybatis查询数据库返回结果为空