学到了mybatis,在进行一对一映射的时候报这个异常
### Error building SqlSession. ### The error may exist in StudentMapper.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. The XML location is 'StudentMapper.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
其实这个异常报的还挺明确的,这个是映射文件也就是StudentMapper.xml里面的代码
//注意下面这一行的type
也有相对应的文件
我的出错原因是在配置文件里面mybatis-config.xml。这里面没有给Address起别名。(因为在resultMap里面的type属性使用的是Address,所以别名就叫Address)
(type里面是这个类的全限定名,把address加上就可以了)
这个标签里面还可以使用package把一个目录下的所有类都起默认名
(使用package就不用加类名了)
这样就能正常运行了。



