Skip to content

Commit 87bc640

Browse files
author
Washmore
committed
修复指定编码对service文件不生效的bug;
washmore
1 parent b149af3 commit 87bc640

File tree

1 file changed

+11
-30
lines changed

1 file changed

+11
-30
lines changed

autocode.core/src/main/java/tech/washmore/autocode/core/generator/mysql/MysqlAbstractServiceClassGenerator.java

+11-30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tech.washmore.autocode.core.generator.mysql;
22

33
import tech.washmore.autocode.core.config.ConfigManager;
4+
import tech.washmore.autocode.core.generator.base.AutoCodeFileWriter;
45
import tech.washmore.autocode.model.Constants;
56
import tech.washmore.autocode.model.config.*;
67
import tech.washmore.autocode.model.enums.DataFileMethod;
@@ -48,17 +49,6 @@ private void generateServiceExtends(TableModel tm) throws IOException {
4849
Doc doc = config.getDoc();
4950
Project project = config.getProject();
5051

51-
File dic = new File(project.getPath() + Constants.pathSplitor + project.getJavaRoot() + Constants.pathSplitor + service.getExtendsPackagePath());
52-
if (!dic.exists()) {
53-
dic.mkdirs();
54-
}
55-
56-
File file = new File(dic, tm.getClsName() + service.getSuffix() + ".java");
57-
if (file.exists()) {
58-
return;
59-
}
60-
file.createNewFile();
61-
6252
StringBuffer sb = new StringBuffer("");
6353
sb.append("package ").append(service.getExtendsPackageName()).append(";").append(System.lineSeparator()).append(System.lineSeparator());
6454
sb.append("import org.springframework.stereotype.Service;").append(System.lineSeparator());
@@ -78,11 +68,11 @@ private void generateServiceExtends(TableModel tm) throws IOException {
7868
.append(System.lineSeparator());
7969
sb.append("}");
8070

81-
OutputStream ops = new FileOutputStream(file);
82-
ops.write(sb.toString().getBytes());
83-
ops.flush();
84-
ops.close();
85-
System.out.println("\t输出文件:" + file.getPath().replace(new File(config.getProject().getPath()).getPath(), ""));
71+
AutoCodeFileWriter.writeStringToFile(
72+
project.getPath() + Constants.pathSplitor + project.getJavaRoot()
73+
+ Constants.pathSplitor + service.getExtendsPackagePath(),
74+
tm.getClsName() + service.getSuffix() + ".java", sb.toString(), false
75+
);
8676
}
8777

8878
private void generateService(TableModel tm) throws IOException {
@@ -169,21 +159,12 @@ private void generateService(TableModel tm) throws IOException {
169159

170160
insertDependencies(sb, tm);
171161

172-
File dic = new File(project.getPath() + Constants.pathSplitor + project.getJavaRoot() + Constants.pathSplitor + service.getBasePackagePath());
173-
if (!dic.exists()) {
174-
dic.mkdirs();
175-
}
162+
AutoCodeFileWriter.writeStringToFile(
163+
project.getPath() + Constants.pathSplitor + project.getJavaRoot()
164+
+ Constants.pathSplitor + service.getBasePackagePath(),
165+
tm.getClsName() + service.getBaseSuffix() + ".java", sb.toString(), true
166+
);
176167

177-
File file = new File(dic, tm.getClsName() + service.getBaseSuffix() + ".java");
178-
if (file.exists()) {
179-
file.delete();
180-
}
181-
file.createNewFile();
182-
OutputStream ops = new FileOutputStream(file);
183-
ops.write(sb.toString().getBytes());
184-
ops.flush();
185-
ops.close();
186-
System.out.println("\t输出文件:" + file.getPath().replace(new File(config.getProject().getPath()).getPath(), ""));
187168
}
188169

189170

0 commit comments

Comments
 (0)