W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
在 Hasor3 之后,由于 ApiBinder 擴(kuò)展機(jī)制的引入,ApiBinder 變可以隨時(shí)進(jìn)行擴(kuò)展。下面我們展現(xiàn)一下相關(guān)特性。例:擴(kuò)展 Apibinder 并在自己的 TestBinder 上實(shí)現(xiàn)一個(gè) Hello Word 方法。
package net.test.binder;
public interface TestBinder extends ApiBinder {
public void hello();
}
public class TestBinderImpl extends ApiBinderWrap implements TestBinder {
public TestBinderImpl(ApiBinder apiBinder) {
super(apiBinder);
}
public void hello() {
System.out.println("Hello Binder");
}
}
public class TestBinderCreater implements ApiBinderCreater {
public TestBinder createBinder(ApiBinder apiBinder) {
return new TestBinderImpl(apiBinder);
}
}
接著我們需要在配置文件中增加如下配置:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://project.hasor.net/hasor/schema/main">
<hasor.apiBinderSet>
<binder type="net.test.binder.TestBinder">net.test.binder.TestBinderCreater</binder>
</hasor.apiBinderSet>
</config>
最后我們?cè)?Hasor 的啟動(dòng)Module中使用這個(gè)自定義的 ApiBinder
package net.test.hasor;
public class HelloModule implements Module {
public void loadModule(ApiBinder apiBinder) throws Throwable {
TestBinder myBinder = (TestBinder)apiBinder;
myBinder.hello();
}
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: