From fb6eafb24d8898cb67c859e6205ee34bfe093dfb Mon Sep 17 00:00:00 2001 From: charle004 <937002632@qq.com> Date: Thu, 5 Sep 2024 10:47:51 +0800 Subject: [PATCH] support multiple mapper-locations --- .../contrib/ngbatis/NgbatisContextInitializer.java | 2 +- .../nebula/contrib/ngbatis/config/ParseCfgProps.java | 8 ++++---- .../contrib/ngbatis/io/MapperResourceLoader.java | 10 ++++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/nebula/contrib/ngbatis/NgbatisContextInitializer.java b/src/main/java/org/nebula/contrib/ngbatis/NgbatisContextInitializer.java index 51f3653..1e124ee 100644 --- a/src/main/java/org/nebula/contrib/ngbatis/NgbatisContextInitializer.java +++ b/src/main/java/org/nebula/contrib/ngbatis/NgbatisContextInitializer.java @@ -62,7 +62,7 @@ private ParseCfgProps readParseCfgProps(ConfigurableEnvironment environment) { .setLogShow(environment.getProperty("cql.parser.log-show")) .setMapper(environment.getProperty("cql.parser.mapper")) .setNamespace(environment.getProperty("cql.parser.namespace")) - .setMapperLocations(environment.getProperty("cql.parser.mapper-locations")) + .setMapperLocations(environment.getProperty("cql.parser.mapper-locations", String[].class)) .setMapperTplLocation(environment.getProperty("cql.parser.mapper-tpl-location")) .setResultType(environment.getProperty("cql.parser.result-type")) .setParameterType(environment.getProperty("cql.parser.parameter-type")) diff --git a/src/main/java/org/nebula/contrib/ngbatis/config/ParseCfgProps.java b/src/main/java/org/nebula/contrib/ngbatis/config/ParseCfgProps.java index 89f700a..2b94c76 100644 --- a/src/main/java/org/nebula/contrib/ngbatis/config/ParseCfgProps.java +++ b/src/main/java/org/nebula/contrib/ngbatis/config/ParseCfgProps.java @@ -25,7 +25,7 @@ public class ParseCfgProps { private String mapperTplLocation = "NebulaDaoBasic.xml"; - private String mapperLocations = "mapper/**/*.xml"; + private String[] mapperLocations = {"mapper/**/*.xml"}; private String id = "id"; @@ -75,7 +75,7 @@ public ParseCfgProps setMapperTplLocation(String mapperTplLocation) { *

获取开发者业务dao对应xml所存放的路径。

* @return 开发者业务dao对应xml所存放的路径 */ - public String getMapperLocations() { + public String[] getMapperLocations() { return mapperLocations; } @@ -84,8 +84,8 @@ public String getMapperLocations() { * @param mapperLocations 业务dao对应xml所存放的路径 * @return 解析配置(本应是 void,为支持链式调用而改) */ - public ParseCfgProps setMapperLocations(String mapperLocations) { - if (isBlank(mapperLocations)) { + public ParseCfgProps setMapperLocations(String[] mapperLocations) { + if (isEmpty(mapperLocations)) { return this; } this.mapperLocations = mapperLocations; diff --git a/src/main/java/org/nebula/contrib/ngbatis/io/MapperResourceLoader.java b/src/main/java/org/nebula/contrib/ngbatis/io/MapperResourceLoader.java index ce7e196..7c534d9 100644 --- a/src/main/java/org/nebula/contrib/ngbatis/io/MapperResourceLoader.java +++ b/src/main/java/org/nebula/contrib/ngbatis/io/MapperResourceLoader.java @@ -87,11 +87,13 @@ public MapperResourceLoader(ParseCfgProps parseConfig,ApplicationContext applica @TimeLog(name = "xml-load", explain = "mappers xml load completed : {} ms") public Map load() { Map resultClassModel = new HashMap<>(); - String mapperLocations = parseConfig.getMapperLocations(); + String[] mapperLocations = parseConfig.getMapperLocations(); try { - Resource[] resources = getResources(mapperLocations); - for (Resource resource : resources) { - resultClassModel.putAll(parseClassModel(resource)); + for (String mapperLocation : mapperLocations) { + Resource[] resources = getResources(mapperLocation); + for (Resource resource : resources) { + resultClassModel.putAll(parseClassModel(resource)); + } } } catch (FileNotFoundException ffe) { log.warn("No mapper files were found in path pattern '{}', please add", mapperLocations);