feat: 生成的每类文件,单独支持是否覆盖源文件。

This commit is contained in:
Suomm 2023-05-17 20:49:31 +08:00
parent ed1a3c0938
commit 0cc1ba76d8
15 changed files with 308 additions and 244 deletions

View File

@ -1,17 +1,17 @@
/**
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.codegen.config;
@ -39,6 +39,11 @@ public class ControllerConfig {
*/
private Class<?> supperClass;
/**
* 是否覆盖之前生成的文件
*/
private boolean overwriteEnable;
/**
* 生成 REST 风格的 Controller
*/
@ -79,6 +84,15 @@ public class ControllerConfig {
return this;
}
public boolean isOverwriteEnable() {
return overwriteEnable;
}
public ControllerConfig setOverwriteEnable(boolean overwriteEnable) {
this.overwriteEnable = overwriteEnable;
return this;
}
public boolean isRestStyle() {
return restStyle;
}

View File

@ -1,17 +1,17 @@
/**
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.codegen.config;
@ -41,6 +41,11 @@ public class EntityConfig {
*/
private Class<?> supperClass;
/**
* 是否覆盖之前生成的文件
*/
private boolean overwriteEnable;
/**
* Entity 默认实现的接口
*/
@ -78,6 +83,15 @@ public class EntityConfig {
return this;
}
public boolean isOverwriteEnable() {
return overwriteEnable;
}
public EntityConfig setOverwriteEnable(boolean overwriteEnable) {
this.overwriteEnable = overwriteEnable;
return this;
}
public Class<?>[] getImplInterfaces() {
return implInterfaces;
}

View File

@ -1,17 +1,17 @@
/**
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.codegen.config;
@ -41,6 +41,11 @@ public class MapperConfig {
*/
private Class<?> supperClass = BaseMapper.class;
/**
* 是否覆盖之前生成的文件
*/
private boolean overwriteEnable;
public String buildSuperClassImport() {
return supperClass.getName();
}
@ -76,4 +81,13 @@ public class MapperConfig {
return this;
}
public boolean isOverwriteEnable() {
return overwriteEnable;
}
public MapperConfig setOverwriteEnable(boolean overwriteEnable) {
this.overwriteEnable = overwriteEnable;
return this;
}
}

View File

@ -34,6 +34,11 @@ public class MapperXmlConfig {
*/
private String fileSuffix = "Mapper";
/**
* 是否覆盖之前生成的文件
*/
private boolean overwriteEnable;
public String getFilePrefix() {
return filePrefix;
}
@ -52,4 +57,13 @@ public class MapperXmlConfig {
return this;
}
public boolean isOverwriteEnable() {
return overwriteEnable;
}
public MapperXmlConfig setOverwriteEnable(boolean overwriteEnable) {
this.overwriteEnable = overwriteEnable;
return this;
}
}

View File

@ -1,17 +1,17 @@
/**
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.codegen.config;
@ -41,6 +41,11 @@ public class ServiceConfig {
*/
private Class<?> supperClass = IService.class;
/**
* 是否覆盖之前生成的文件
*/
private boolean overwriteEnable;
public String buildSuperClassImport() {
return supperClass.getName();
}
@ -76,4 +81,13 @@ public class ServiceConfig {
return this;
}
public boolean isOverwriteEnable() {
return overwriteEnable;
}
public ServiceConfig setOverwriteEnable(boolean overwriteEnable) {
this.overwriteEnable = overwriteEnable;
return this;
}
}

View File

@ -1,17 +1,17 @@
/**
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.codegen.config;
@ -41,6 +41,11 @@ public class ServiceImplConfig {
*/
private Class<?> supperClass = ServiceImpl.class;
/**
* 是否覆盖之前生成的文件
*/
private boolean overwriteEnable;
public String buildSuperClassImport() {
return supperClass.getName();
}
@ -76,4 +81,13 @@ public class ServiceImplConfig {
return this;
}
public boolean isOverwriteEnable() {
return overwriteEnable;
}
public ServiceImplConfig setOverwriteEnable(boolean overwriteEnable) {
this.overwriteEnable = overwriteEnable;
return this;
}
}

View File

@ -16,9 +16,6 @@
package com.mybatisflex.codegen.config;
import com.mybatisflex.codegen.template.ITemplate;
import com.mybatisflex.codegen.template.impl.EnjoyTemplate;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -33,11 +30,6 @@ import java.util.Set;
@SuppressWarnings("unused")
public class StrategyConfig {
/**
* 使用哪个模板引擎来生成代码
*/
protected ITemplate templateEngine;
/**
* 数据库表前缀多个前缀用英文逗号, 隔开
*/
@ -58,11 +50,6 @@ public class StrategyConfig {
*/
private boolean generateForView;
/**
* 是否覆盖之前生成的文件
*/
private boolean overwriteEnable;
/**
* 单独为某张表添加独立的配置
*/
@ -185,18 +172,6 @@ public class StrategyConfig {
return false;
}
public ITemplate getTemplateEngine() {
if (templateEngine == null) {
templateEngine = new EnjoyTemplate();
}
return templateEngine;
}
public StrategyConfig setTemplateEngine(ITemplate templateEngine) {
this.templateEngine = templateEngine;
return this;
}
public String getTablePrefix() {
return tablePrefix;
}
@ -233,15 +208,6 @@ public class StrategyConfig {
return this;
}
public boolean isOverwriteEnable() {
return overwriteEnable;
}
public StrategyConfig setOverwriteEnable(boolean overwriteEnable) {
this.overwriteEnable = overwriteEnable;
return this;
}
public Map<String, TableConfig> getTableConfigMap() {
return tableConfigMap;
}

View File

@ -1,17 +1,17 @@
/**
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.codegen.config;
@ -34,6 +34,11 @@ public class TableDefConfig {
*/
private String classSuffix = "Def";
/**
* 是否覆盖之前生成的文件
*/
private boolean overwriteEnable;
public String getClassPrefix() {
return classPrefix;
}
@ -52,4 +57,13 @@ public class TableDefConfig {
return this;
}
public boolean isOverwriteEnable() {
return overwriteEnable;
}
public TableDefConfig setOverwriteEnable(boolean overwriteEnable) {
this.overwriteEnable = overwriteEnable;
return this;
}
}

View File

@ -1,23 +1,23 @@
/**
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.codegen.generator.impl;
import com.mybatisflex.codegen.config.ControllerConfig;
import com.mybatisflex.codegen.config.GlobalConfig;
import com.mybatisflex.codegen.config.PackageConfig;
import com.mybatisflex.codegen.config.StrategyConfig;
import com.mybatisflex.codegen.constant.TemplateConst;
import com.mybatisflex.codegen.entity.Table;
import com.mybatisflex.codegen.generator.IGenerator;
@ -52,14 +52,14 @@ public class ControllerGenerator implements IGenerator {
}
PackageConfig packageConfig = globalConfig.getPackageConfig();
StrategyConfig strategyConfig = globalConfig.getStrategyConfig();
ControllerConfig controllerConfig = globalConfig.getControllerConfig();
String controllerPackagePath = packageConfig.getControllerPackage().replace(".", "/");
File controllerJavaFile = new File(packageConfig.getSourceDir(), controllerPackagePath + "/" +
table.buildControllerClassName() + ".java");
if (controllerJavaFile.exists() && strategyConfig.isOverwriteEnable()) {
if (controllerJavaFile.exists() && controllerConfig.isOverwriteEnable()) {
return;
}
@ -67,8 +67,8 @@ public class ControllerGenerator implements IGenerator {
Map<String, Object> params = new HashMap<>(4);
params.put("table", table);
params.put("packageConfig", packageConfig);
params.put("controllerConfig", controllerConfig);
params.put("javadocConfig", globalConfig.getJavadocConfig());
params.put("controllerConfig", globalConfig.getControllerConfig());
globalConfig.getTemplateConfig().getTemplate().generate(params, templatePath, controllerJavaFile);
}

View File

@ -1,23 +1,23 @@
/**
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.codegen.generator.impl;
import com.mybatisflex.codegen.config.EntityConfig;
import com.mybatisflex.codegen.config.GlobalConfig;
import com.mybatisflex.codegen.config.PackageConfig;
import com.mybatisflex.codegen.config.StrategyConfig;
import com.mybatisflex.codegen.constant.TemplateConst;
import com.mybatisflex.codegen.entity.Table;
import com.mybatisflex.codegen.generator.IGenerator;
@ -52,22 +52,22 @@ public class EntityGenerator implements IGenerator {
}
PackageConfig packageConfig = globalConfig.getPackageConfig();
StrategyConfig strategyConfig = globalConfig.getStrategyConfig();
EntityConfig entityConfig = globalConfig.getEntityConfig();
String entityPackagePath = packageConfig.getEntityPackage().replace(".", "/");
File entityJavaFile = new File(packageConfig.getSourceDir(), entityPackagePath + "/" +
table.buildEntityClassName() + ".java");
if (entityJavaFile.exists() && !strategyConfig.isOverwriteEnable()) {
if (entityJavaFile.exists() && !entityConfig.isOverwriteEnable()) {
return;
}
Map<String, Object> params = new HashMap<>(4);
params.put("table", table);
params.put("entityConfig", entityConfig);
params.put("packageConfig", packageConfig);
params.put("entityConfig", globalConfig.getEntityConfig());
params.put("javadocConfig", globalConfig.getJavadocConfig());
globalConfig.getTemplateConfig().getTemplate().generate(params, templatePath, entityJavaFile);

View File

@ -1,23 +1,23 @@
/**
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.codegen.generator.impl;
import com.mybatisflex.codegen.config.GlobalConfig;
import com.mybatisflex.codegen.config.MapperConfig;
import com.mybatisflex.codegen.config.PackageConfig;
import com.mybatisflex.codegen.config.StrategyConfig;
import com.mybatisflex.codegen.constant.TemplateConst;
import com.mybatisflex.codegen.entity.Table;
import com.mybatisflex.codegen.generator.IGenerator;
@ -52,22 +52,22 @@ public class MapperGenerator implements IGenerator {
}
PackageConfig packageConfig = globalConfig.getPackageConfig();
StrategyConfig strategyConfig = globalConfig.getStrategyConfig();
MapperConfig mapperConfig = globalConfig.getMapperConfig();
String mapperPackagePath = packageConfig.getMapperPackage().replace(".", "/");
File mapperJavaFile = new File(packageConfig.getSourceDir(), mapperPackagePath + "/" +
table.buildMapperClassName() + ".java");
if (mapperJavaFile.exists() && !strategyConfig.isOverwriteEnable()) {
if (mapperJavaFile.exists() && !mapperConfig.isOverwriteEnable()) {
return;
}
Map<String, Object> params = new HashMap<>(4);
params.put("table", table);
params.put("mapperConfig", mapperConfig);
params.put("packageConfig", packageConfig);
params.put("mapperConfig", globalConfig.getMapperConfig());
params.put("javadocConfig", globalConfig.getJavadocConfig());
globalConfig.getTemplateConfig().getTemplate().generate(params, templatePath, mapperJavaFile);

View File

@ -1,23 +1,23 @@
/**
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.codegen.generator.impl;
import com.mybatisflex.codegen.config.GlobalConfig;
import com.mybatisflex.codegen.config.MapperXmlConfig;
import com.mybatisflex.codegen.config.PackageConfig;
import com.mybatisflex.codegen.config.StrategyConfig;
import com.mybatisflex.codegen.constant.TemplateConst;
import com.mybatisflex.codegen.entity.Table;
import com.mybatisflex.codegen.generator.IGenerator;
@ -52,13 +52,13 @@ public class MapperXmlGenerator implements IGenerator {
}
PackageConfig packageConfig = globalConfig.getPackageConfig();
StrategyConfig strategyConfig = globalConfig.getStrategyConfig();
MapperXmlConfig mapperXmlConfig = globalConfig.getMapperXmlConfig();
File mapperXmlFile = new File(packageConfig.getMapperXmlPath() + "/" +
table.buildMapperXmlFileName() + ".xml");
if (mapperXmlFile.exists() && !strategyConfig.isOverwriteEnable()) {
if (mapperXmlFile.exists() && !mapperXmlConfig.isOverwriteEnable()) {
return;
}

View File

@ -1,23 +1,23 @@
/**
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.codegen.generator.impl;
import com.mybatisflex.codegen.config.GlobalConfig;
import com.mybatisflex.codegen.config.PackageConfig;
import com.mybatisflex.codegen.config.StrategyConfig;
import com.mybatisflex.codegen.config.ServiceConfig;
import com.mybatisflex.codegen.constant.TemplateConst;
import com.mybatisflex.codegen.entity.Table;
import com.mybatisflex.codegen.generator.IGenerator;
@ -52,22 +52,22 @@ public class ServiceGenerator implements IGenerator {
}
PackageConfig packageConfig = globalConfig.getPackageConfig();
StrategyConfig strategyConfig = globalConfig.getStrategyConfig();
ServiceConfig serviceConfig = globalConfig.getServiceConfig();
String servicePackagePath = packageConfig.getServicePackage().replace(".", "/");
File serviceJavaFile = new File(packageConfig.getSourceDir(), servicePackagePath + "/" +
table.buildServiceClassName() + ".java");
if (serviceJavaFile.exists() && !strategyConfig.isOverwriteEnable()) {
if (serviceJavaFile.exists() && !serviceConfig.isOverwriteEnable()) {
return;
}
Map<String, Object> params = new HashMap<>(4);
params.put("table", table);
params.put("serviceConfig", serviceConfig);
params.put("packageConfig", packageConfig);
params.put("serviceConfig", globalConfig.getServiceConfig());
params.put("javadocConfig", globalConfig.getJavadocConfig());
globalConfig.getTemplateConfig().getTemplate().generate(params, templatePath, serviceJavaFile);

View File

@ -1,23 +1,23 @@
/**
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.codegen.generator.impl;
import com.mybatisflex.codegen.config.GlobalConfig;
import com.mybatisflex.codegen.config.PackageConfig;
import com.mybatisflex.codegen.config.StrategyConfig;
import com.mybatisflex.codegen.config.ServiceImplConfig;
import com.mybatisflex.codegen.constant.TemplateConst;
import com.mybatisflex.codegen.entity.Table;
import com.mybatisflex.codegen.generator.IGenerator;
@ -52,14 +52,14 @@ public class ServiceImplGenerator implements IGenerator {
}
PackageConfig packageConfig = globalConfig.getPackageConfig();
StrategyConfig strategyConfig = globalConfig.getStrategyConfig();
ServiceImplConfig serviceImplConfig = globalConfig.getServiceImplConfig();
String serviceImplPackagePath = packageConfig.getServiceImplPackage().replace(".", "/");
File serviceImplJavaFile = new File(packageConfig.getSourceDir(), serviceImplPackagePath + "/" +
table.buildServiceImplClassName() + ".java");
if (serviceImplJavaFile.exists() && !strategyConfig.isOverwriteEnable()) {
if (serviceImplJavaFile.exists() && !serviceImplConfig.isOverwriteEnable()) {
return;
}
@ -67,8 +67,8 @@ public class ServiceImplGenerator implements IGenerator {
Map<String, Object> params = new HashMap<>(4);
params.put("table", table);
params.put("packageConfig", packageConfig);
params.put("serviceImplConfig", serviceImplConfig);
params.put("javadocConfig", globalConfig.getJavadocConfig());
params.put("serviceImplConfig", globalConfig.getServiceImplConfig());
globalConfig.getTemplateConfig().getTemplate().generate(params, templatePath, serviceImplJavaFile);
}

View File

@ -1,23 +1,23 @@
/**
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.codegen.generator.impl;
import com.mybatisflex.codegen.config.GlobalConfig;
import com.mybatisflex.codegen.config.PackageConfig;
import com.mybatisflex.codegen.config.StrategyConfig;
import com.mybatisflex.codegen.config.TableDefConfig;
import com.mybatisflex.codegen.constant.TemplateConst;
import com.mybatisflex.codegen.entity.Table;
import com.mybatisflex.codegen.generator.IGenerator;
@ -52,14 +52,14 @@ public class TableDefGenerator implements IGenerator {
}
PackageConfig packageConfig = globalConfig.getPackageConfig();
StrategyConfig strategyConfig = globalConfig.getStrategyConfig();
TableDefConfig tableDefConfig = globalConfig.getTableDefConfig();
String tableDefPackagePath = packageConfig.getTableDefPackage().replace(".", "/");
File tableDefJavaFile = new File(packageConfig.getSourceDir(), tableDefPackagePath + "/" +
table.buildTableDefClassName() + ".java");
if (tableDefJavaFile.exists() && !strategyConfig.isOverwriteEnable()) {
if (tableDefJavaFile.exists() && !tableDefConfig.isOverwriteEnable()) {
return;
}
@ -67,8 +67,8 @@ public class TableDefGenerator implements IGenerator {
Map<String, Object> params = new HashMap<>(4);
params.put("table", table);
params.put("packageConfig", packageConfig);
params.put("tableDefConfig", tableDefConfig);
params.put("javadocConfig", globalConfig.getJavadocConfig());
params.put("tableDefConfig", globalConfig.getTableDefConfig());
globalConfig.getTemplateConfig().getTemplate().generate(params, templatePath, tableDefJavaFile);
}