Mybatis resultMap启动时报错:Could not resolve type alias 'empno Cannot find class: empno

Po扩展类,继承用Mybatis-Gernerator工具生成的原始的Dept类,里面再包含了一个User对象

public class DeptExtends extends Dept {

//扩展类包含一个对象
public Emp emp;
public Emp getEmp() {
return emp;
}
public void setEmp(Emp emp) {
this.emp = emp;
}



DeptExtendMapper.xml

<!--通过resultMap来接受结果集 -->
      <resultMap type="com.it.mybatis.po.DeptExtends" id="SelectDeptEmpMap">
      <!-- 配置映射的Dept信息:主查询方 -->
      <!-- id为唯一标示符,如果有两个列可以唯一标示,两个都写 
          result:非唯一标示符的字段
          column:数据库的字段
          property:java类属性
      -->
      <id column="deptno" property="deptno"></id>
      <result column="dname" property="dname"></result>
      <result column="loc" property="loc"></result>
     
      <!-- 配置映射的关联emp信息 -->
      <!-- property:外包装类DeptExtends的中的属性 
      javaType:property所在的类
      -->
      <association property="emp" javaType="com.it.mybatis.po.Emp">
      <id column="empno" javaType="empno"/>    --------改成 property即可
      <result column="job" property="job"/>
      <result column="sal" property="sal"/>
      <result column="comm" property="comm"/>
      <result column="deptno" property="deptno"/>
      <result column="hiredate" property="hiredate"/>
      </association>
      </resultMap>
     <select id="FindDeptEmp" resultMap="SelectDeptEmpMap">
      select dept.*,emp.empno,emp.ename,emp.job,emp.mgr,emp.sal,emp.comm,emp.hiredate from dept,emp
             where dept.deptno=emp.deptno
     </select>
      


错误在于上面的配置文件id写成了javaType





Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'empno'.  Cause: java.lang.ClassNotFoundException: Cannot find class: empno

at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:118)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildResultMappingFromContext(XMLMapperBuilder.java:374)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:280)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.processNestedResultMappings(XMLMapperBuilder.java:386)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildResultMappingFromContext(XMLMapperBuilder.java:366)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:280)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:252)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:244)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:116)
... 51 more
Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias 'empno'.  Cause: java.lang.ClassNotFoundException: Cannot find class: empno
at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:120)
at org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:149)
at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:116)
... 59 more
Caused by: java.lang.ClassNotFoundException: Cannot find class: empno
at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:200)
at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:89)
at org.apache.ibatis.io.Resources.classForName(Resources.java:261)
at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:116)
... 61 more

没有更多推荐了,返回首页