You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MyBatis Plus+Spring Boot解析mapper.xml遇类找不到异常求助

问题分析与解决方案

1. 内部类全限定名引用错误

MyBatis解析Java静态内部类时,必须使用$符号分隔外部类和内部类,而非.。你在mapper.xml中用.连接内部类,导致类加载失败,触发ClassNotFoundException。

正确的类引用格式:

  • 外部类:entity.StudentCourseDetailsRes
  • CourseDtls静态内部类:entity.StudentCourseDetailsRes$CourseDtls
  • ErrDetails静态内部类:entity.StudentCourseDetailsRes$CourseDtls$ErrDetails

2. ResultMap配置冗余错误

你的resultMap中嵌套了多余的<collection property="courseDtls">,但CourseDtls类并无courseDtls属性,这会导致映射逻辑错误,同时加重类加载异常的影响。

修正后的mapper.xml配置

<mapper namespace="mapper.StudentMapper">
    <select id="studentproc" statementType="CALLABLE" parameterType="java.util.Map" resultMap="stuCourse">
     {call package.student_course_proc(
#{stuId, jdbcType=VARCHAR,javaType=java.lang.String,mode=IN},#{courseName, jdbcType=VARCHAR,javaType=java.lang.String,mode=OUT},#{couseDetails, jdbcType=VARCHAR,javaType=java.lang.String,mode=OUT},#{errorCode, jdbcType=VARCHAR,javaType=java.lang.String,mode=OUT},#{errorMessage, jdbcType=VARCHAR,javaType=java.lang.String,mode=OUT}
   )}
    </select>
  <resultMap id="stuCourse" type="entity.StudentCourseDetailsRes">
     <collection property="courseDtlsList" ofType="entity.StudentCourseDetailsRes$CourseDtls">
          <result property="courseName" />
          <result property="courseDuration"/>
          <collection property="errorDetailList" ofType="entity.StudentCourseDetailsRes$CourseDtls$ErrDetails">
            <result property="errorCode"/>
            <result property="errorMessage"/>
         </collection>
     </collection>
  </resultMap>
</mapper>

额外修正点

  • 实体类ErrDetails中属性errorCode和errorMessage的类型写为小写string,属于Java语法错误,需改为大写String:
private String errorCode;
private String errorMessage;
  • 原存储过程调用语句缺失闭合括号),已在修正后的代码中补充。

内容的提问来源于stack exchange,提问作者user3898783

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 01:09:28