第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

MyBatis的Mapper支持繼承么?或者類(lèi)似的解決方案?

MyBatis的Mapper支持繼承么?或者類(lèi)似的解決方案?

遠(yuǎn)看寒山石徑斜 2018-03-23 14:04:50
查看完整描述

1 回答

?
Qyou

TA貢獻(xiàn)8條經(jīng)驗(yàn) 獲得超4個(gè)贊

Mybatis實(shí)際上隱藏了一個(gè)功能:Mapper.xml可以繼承,這個(gè)在官方文檔中并沒(méi)有提到過(guò),不過(guò)在這個(gè)issue?(commit)里提到過(guò)。

Statement覆蓋

利用Mapper.xml的繼承機(jī)制,我們可以做到ChildMapper覆蓋ParentMapper中selectinsert、delete、update。下面舉例說(shuō)明:

Interface:

@MybatisMapperpublic?interface?ParentMapper?{??String?selectFoo();??String?selectBar();
}@MybatisMapperpublic?interface?ChildMapper?extends?ParentMapper?{??String?selectLoo();

}

Mapper.xml:

<mapper?namespace="me.chanjar.mybatislearn.inherit.statement.ParentMapper">

??<select?id="selectFoo"?resultType="String">
????SELECT?'Foo?From?Parent'
????FROM?dual??</select>

??<select?id="selectBar"?resultType="String">
????SELECT?'Bar?From?Parent'
????FROM?dual??</select></mapper><mapper?namespace="me.chanjar.mybatislearn.inherit.statement.ChildMapper">

??<!--?覆蓋?Parent.selectFoo的定義?-->
??<select?id="selectFoo"?resultType="String">
????SELECT?'Foo?From?Child'
????FROM?dual??</select>

??<!--?不覆蓋?Parent.selectBar的定義?-->

??<!--?自己的?Child.selectLoo的定義?-->
??<select?id="selectLoo"?resultType="String">
????SELECT?'Loo?From?Child'
????FROM?dual??</select></mapper>

規(guī)律可以總結(jié)為:

  1. ParentMapper.xml中有,ChildMapper.xml中沒(méi)有,ChildMapper沿用ParentMapper.xml中的定義

  2. ParentMapper.xml中有,ChildMapper.xml中也有,ChildMapper使用ChildMapper.xml中的定義

  3. ParentMapper.xml中沒(méi)有,ChildMapper.xml中有,ChildMapper使用ChildMapper.xml中的定義


查看完整回答
反對(duì) 回復(fù) 2018-03-23
  • 1 回答
  • 0 關(guān)注
  • 3023 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)