Mybatis mapping文件中 數據封裝類使用內部類
阿新 • • 發佈:2017-10-02
awr map 成員 wrapper color ner 加載 加載器 結果
在一般的應用中,都會采用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又可正常加載了。
Mybatis mapping文件中 數據封裝類使用內部類