1 sql配置文件java
<sql id="Base_Column_List"> <!-- WARNING - @mbggenerated This element is automatically generated by MyBatis Generator, do not modify. This element was generated on Fri Aug 14 16:08:36 CST 2015. --> Id, menu_name, menu_remark, menu_parent_id, menu_url, is_show, is_delete, operation_user_name, operation_time </sql>
2 代碼sql
private void sqlElement(List<XNode> list) throws Exception { // 當全局配置中數據庫產品名稱不爲null,先遍歷通常SQL if (configuration.getDatabaseId() != null) { sqlElement(list, configuration.getDatabaseId()); } sqlElement(list, null); } private void sqlElement(List<XNode> list, String requiredDatabaseId) throws Exception { for (XNode context : list) { // null String databaseId = context.getStringAttribute("databaseId"); // Base_Column_List String id = context.getStringAttribute("id"); // cn.vansky.schedule.time.menu.dao.MenuMapper.Base_Column_List id = builderAssistant.applyCurrentNamespace(id, false); // 一致,須要添加到sqlFragments裏面 if (databaseIdMatchesCurrent(id, databaseId, requiredDatabaseId)) sqlFragments.put(id, context); } } // 匹配當前配置的數據庫是否與默認的數據庫一致 private boolean databaseIdMatchesCurrent(String id, String databaseId, String requiredDatabaseId) { if (requiredDatabaseId != null) { // 當全局配置的數據庫產品名稱與配置的產品名稱不同,就不須要添加內容到sqlFragment裏面 if (!requiredDatabaseId.equals(databaseId)) { return false; } } else { if (databaseId != null) { return false; } // skip this fragment if there is a previous one with a not null databaseId if (this.sqlFragments.containsKey(id)) { XNode context = this.sqlFragments.get(id); if (context.getStringAttribute("databaseId") != null) { return false; } } } return true; }
對多個SQL配置進行遍歷。這裏再也不過多分析,下面就是最終結果。數據庫
這裏爲何一次put生成2個對象呢,是由於MyBatis使用本身的StrictMap,在put方法裏進行了重寫。app