记一个菜鸟犯的错误

来源:互联网 发布:淘宝情趣内衣图片无码 编辑:程序博客网 时间:2024/06/05 18:44

刚开始接触mybatis,写一个小项目的时候出现了一个错误,因为是菜鸟,所以解决了好久,趁着有空就记一下,警示自己,帮助他人。




dao和domain如上图(因为是练手,为了看着方便,所以mapper.xml就跟dao放一起了,没有分开)




配置文件也只有这些。




spring与mybatis的配置




其中一个mapper是这样的,另外一个也是这么写的。

报错如下:


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 'Teacher'.  Cause:java.lang.ClassNotFoundException: Cannot find class: Teacher

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

Caused by: org.apache.ibatis.type.TypeException:Could not resolve type alias 'Teacher'. Cause: java.lang.ClassNotFoundException: Cannot find class: Teacher

 

ERROR[org.mybatis.spring.mapper.MapperFactoryBean] - Error while adding the mapper'interface cn.kp.dao.TeacherMapper' to configuration.

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 notresolve type alias 'Teacher'.  Cause: java.lang.ClassNotFoundException:Cannot find class: Teacher


查了资料,出这个错大概是因为找不到这个别名,或者sql语句中的resultMap写成了resultType,第二种情况比较好解决,我的属于第一种。这个错一般情况下会给mybits单独写一个配置文件,在配置文件中加入

<typeAlias type=”cn.kp.domain.Teacher” alias=”Teacher”/> 

但是我没有配置文件,我又很任性的不想写,所以只能自己想想怎么解决了 =_=

当然,问题肯定是能解决的,如下图




把别名换成了完全限定名,顺利解决。

0 0
原创粉丝点击