使用MyBatis时报错

发布于:2022-12-27 ⋅ 阅读:(336) ⋅ 点赞:(0)

报错内容如下

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in mapper/usersMapper.xml
### The error occurred while processing mapper_resultMap[usersMap]
### 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 'mapper/usersMapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.zrrd.pojo.User'.  Cause: java.lang.ClassNotFoundException: Cannot find class: com.zrrd.pojo.User
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
    at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
    at com.zrrd.pojo.Test.getSession(Test.java:27)
    at com.zrrd.pojo.Test.selectUsers(Test.java:35)
    at com.zrrd.pojo.Test.main(Test.java:45)

找了很久终于发现了错误

resultMap标签的type错误,修改后成功运行

 

出现这个报错通常是xml文件的问题,建议仔细检查映射文件路径以及select标签中是resultMap还是resultType,希望能对你有所帮助