mybatisはデータベースをクエリーしmapセットを返します

1795 ワード

1.返されるキーを指定しない:学習者idをキーとし、学習者情報をvalueとする集合を返す
JAvaコード(dao実装層)
/**
 *         id key, StudentType   value
 *
 * @return
 */
@Override
public Map getStudentTypeMap() {
    return this.sqlSession.selectMap("StudentTypeMapper.getStudentTypeMap","id");
}

mapperファイル


2.返されるmapの具体的なkeyを指定する
daoレイヤdaoレイヤ:keyをuserPaperとして指定keyをuserPaperとして指定
    public Map getExamPaperRecordMaxScoreByUserIds(String userIds) {
        return sqlSession.selectMap("PaperRecordMapper.getExamPaperRecordMaxScoreByUserIds",userIds,"userPaper");
    }

 
mapperファイル