错误提示:
### Error building SqlSession.
### The error may exist in com/java1234/mappers/AddressMapper.xml
### The error occurred while processing mapper_resultMap[AddressResult]
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Address'. Cause: java.lang.ClassNotFoundException: Cannot find class: Address
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:82)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:66)
at com.java1234.util.SqlSessionFactoryUtil.getSqlSessionFactory(SqlSessionFactoryUtil.java:20)
at com.java1234.util.SqlSessionFactoryUtil.openSession(SqlSessionFactoryUtil.java:29)
at com.java1234.service.StudentTest3.setUp(StudentTest3.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
...
错误原因:
MyBatis配置文件中 mybatis-config.xml中(即总的配置文件)没有对该实体类配置别名;
配置如下:
<typeAliases> <typeAlias alias="Student" type="com.java1234.model.Student"/><!-- 实体类别名配置 --> <typeAlias alias="Address" type="com.java1234.model.Address"/><!-- 实体类别名配置 --> </typeAliases>