mybatis 因为没有设置resultMap id 引起的多结果集异常

mybatis *Mapper.xml 中resultMap的id用来提高整体效能,是比较对象实例时的标识属性,特别是嵌入缓存和结果映射。如果resultMap中不含id项,有可能出现org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 9


    "main.java.com.gazi.survey.bean.SurveyInfo" id="statisticResult">
        <id property = "id" column = "PAPER_ID"/>
        property ="paper" javaType = "Paper">
            <id property = "id" column = "PAPER_ID"/>
            <result property = "title" column = "TITLE"/>
            <result property = "content" column = "CONTENT"/>
            <result property = "sumAnswer" column = "SUM_ANSWER"/>
        
        property="questionInfoList" ofType = "main.java.com.gazi.survey.bean.SurveyInfo$QuestionInfo">
            <id property = "id" column = "QUESTION_ID"/>
            property = "question" javaType = "Question">
                <id property = "id" column = "QUESTION_ID"/>
                <result property = "title" column = "QUESTION_TYPE"/>
                <result property = "type" column = "TYPE"/>
            
            property="questionItemList" ofType = "QuestionItem">
                <id property = "id" column = "QUESTION_ITEM_ID"/>
                <result property = "text" column = "TEXT"/>
                <result property = "checkedNum" column = "CHECKED_NUM"/>
            
        
    

mybatis 因为没有设置resultMap id 引起的多结果集异常_第1张图片
第一个ID数值一致保证了方法返回是POJO时也不会报多结果集异常,第二个QUESTION_ID确定了List中question对象2个,第三个QUESTION_ITEM_ID确定了每个question4个选项。

你可能感兴趣的:(java)