API使用介面匯出

2021-08-29 08:11:25 字數 1305 閱讀 8737

一般的構件都會圍繞乙個主體物件開展,

如: hibernate的session, spring的bean等

通常都需要乙個配置文件, 乙個建造主體物件的工廠

hibernate:

configuration config = new configuration().config(new file("hib.cfg.xml")); // 配置

sessionfactory sessionfactory = config.buildsessionfactory(); // 建立

session session = sessionfactory.opensession(); // 使用

spring:

resource resource = new classpathresource("bean.xml"); // 配置

beanfactory factory = new xmlbeanfactory(resource); // 建立

mybean mybean = (mybean)factory.getbean("mybean"); // 使用

hibernate 使用建造者模式, 封裝了工廠的具體實現,很多框架都使用這種方式匯出(如:freemarker)。

spring 直接new工廠的具體實現, 但多型性更強些,便於擴充套件實現。

meteortl當前選擇的是建造者模式:

configuration config = new configuration(); config.loadconfig("template.xml"); // 配置

// config.adddirective("***.***.***directive"); // 可程式設計控制配置

templatefactory factory = config.buildtemplatefactory(); // 建立

template template = factory.gettemplate("index.mtl"); // 使用

如果模仿spring

resource resource = new classpathresource("template.xml"); // 配置

templatefactory factory = new xmltemplatefactory(resource); // 建立

// factory.adddirective("***.***.***directive"); // 可程式設計控制配置

template template = factory.gettemplate("index.mtl"); // 使用

哪種api使用介面更合理?

簡單的使用API介面

如何簡單的在eclipse上使用api 1我是先在心知天氣上面,註冊了乙個賬號 因為要獲得api的key 可以免費使用天氣的api 2獲取乙個http位址,可以自定義乙個你要查詢的城市的位址,字串拼接,只要將http位址的location放到最後就好了 3輸入乙個位址,然後new乙個url,6.1 ...

api介面 php PHP關於API介面例項分享

api就是作業系統留給應用程式的乙個呼叫介面,應用程式通過呼叫作業系統的 api 而使作業系統去執行應用程式的命令 動作 本文主要和大家分享php關於api介面例項,希望能幫助到大家。php生成json資料 json encode value 方法 response.php和testapi.php ...

介面規範 API介面

同通過網路,規定前後臺資訊互動規則的url連線,是前後臺資訊互動的媒介。1 url 2 請求方式 get post put patch delete 3 請求引數 json或xml格式的key value型別資料 4 響應結果 json或者xml格式的資料 編寫介面文件可以使用去哪網技術中心的乙個開...