Mybatis mapping文件中 数据封装类使用内部类

时间:2022-02-26 15:46:24

在一般的应用中,都会采用ORM 将数据库查出的记录映射为一个实体类,该实体类我们也一般是一个类写在在一个类文件中,但有时候我们会使用内部类,这时候mapping文件配置需注意:

假如该类为:

com.xxx.entity.DataWrapper.InnerEntity

InnerEntity作为DataWrapper的一个公共静态成员,声明时不外乎如下

1、

import com.xxx.entity;

...

DataWrapper.InnerEntity myObject = null;

 

2、

com.xxx.entity.DataWrapper.InnerEntity myObject = null;

 

在Mybatis像如上作为returnType或者paramType是会出现ClassNotFound异常的,这与他的类加载器机制有关,上述类javac编译的内部类结果 是 DataWrapper$InnerEntity.class 文件。

故在配置mapping文件时将 com.xxx.entity.DataWrapper.InnerEntity 改为com.xxx.entity.DataWrapper$InnerEntity ,这样mybatis又可正常加载了。