Mybatis mapping檔案中 資料封裝類使用內部類

來源:互聯網
上載者:User

標籤:port   內部類   obj   bsp   color   載入   成員   type   import   

在一般的應用中,都會採用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檔案中 資料封裝類使用內部類

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.