Skip to content
This repository was archived by the owner on Feb 16, 2022. It is now read-only.

Commit a55fe3f

Browse files
author
gaochen
committed
修改包名
1 parent 1574cb8 commit a55fe3f

File tree

15 files changed

+62
-52
lines changed

15 files changed

+62
-52
lines changed

src/main/java/io/github/gcdd1993/constant/AttributeKey.java renamed to src/main/java/io/github/gcdd1993/jpa/autogen/constant/AttributeKey.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package io.github.gcdd1993.constant;
1+
package io.github.gcdd1993.jpa.autogen.constant;
22

33
/**
4-
* TODO
4+
* 默认的全局变量
5+
* 自定义配置中的'.'会转为'_',目的是解决Freemarker参数的'.'会识别为对象访问属性
56
*
67
* @author gaochen
78
* Created on 2019/6/20.
@@ -18,8 +19,17 @@ public interface AttributeKey {
1819

1920
String REPOSITORY_SIMPLE_NAME_PREFIX = "repository_simple_name_";
2021
String REPOSITORY_FULL_NAME_PREFIX = "repository_full_name_";
22+
String REPOSITORY_PACKAGE = "repository_package";
23+
String REPOSITORY_SUFFIX = "repository_suffix";
24+
String REPOSITORY_TEMPLATE = "repository_template";
2125

2226
String SERVICE_SIMPLE_NAME_PREFIX = "service_simple_name_";
2327
String SERVICE_FULL_NAME_PREFIX = "service_full_name_";
28+
String SERVICE_PACKAGE = "service_package";
29+
String SERVICE_SUFFIX = "service_suffix";
30+
String SERVICE_TEMPLATE = "service_template";
31+
32+
String ENTITY_PACKAGE = "entity_package";
33+
String IMPORT_IGNORE_PACKAGE = "import_ignore_package";
2434

2535
}

src/main/java/io/github/gcdd1993/constant/TemplateKey.java renamed to src/main/java/io/github/gcdd1993/jpa/autogen/constant/TemplateKey.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package io.github.gcdd1993.constant;
1+
package io.github.gcdd1993.jpa.autogen.constant;
22

33
/**
44
* 模板中用到的参数名
5+
* 除了这些,也可以使用{@link AttributeKey}中定义的key,以及配置文件中定义的key,同样的'.'会转为'_'
56
*
67
* @author gaochen
78
* Created on 2019/6/20.
@@ -20,5 +21,4 @@ public interface TemplateKey {
2021
String SERVICE_SIMPLE_NAME = "service_simple_name";
2122
String SERVICE_FULL_NAME = "service_full_name";
2223

23-
2424
}

src/main/java/io/github/gcdd1993/context/ApplicationContext.java renamed to src/main/java/io/github/gcdd1993/jpa/autogen/context/ApplicationContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.gcdd1993.context;
1+
package io.github.gcdd1993.jpa.autogen.context;
22

33
import java.util.Map;
44

src/main/java/io/github/gcdd1993/context/DefaultApplicationContext.java renamed to src/main/java/io/github/gcdd1993/jpa/autogen/context/DefaultApplicationContext.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package io.github.gcdd1993.context;
1+
package io.github.gcdd1993.jpa.autogen.context;
22

3-
import io.github.gcdd1993.model.EntityInfo;
4-
import io.github.gcdd1993.util.ReflectUtils;
3+
import io.github.gcdd1993.jpa.autogen.constant.AttributeKey;
4+
import io.github.gcdd1993.jpa.autogen.model.EntityInfo;
5+
import io.github.gcdd1993.jpa.autogen.util.ReflectUtils;
56
import lombok.Getter;
67
import lombok.RequiredArgsConstructor;
78

@@ -41,7 +42,7 @@ public DefaultApplicationContext(InputStream inputStream) throws IOException {
4142
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
4243
Object key = entry.getKey();
4344
Object value = entry.getValue();
44-
attributes.put(key.toString(), value);
45+
attributes.put(key.toString().replace(".", "_"), value);
4546
}
4647

4748
refresh();
@@ -73,13 +74,13 @@ public void refresh() {
7374
}
7475

7576
private void refreshEntityInfo() {
76-
List<Class<?>> entityClassList = ReflectUtils.getClassListByAnnotation(getAttribute("entity.package", String.class), Entity.class);
77+
List<Class<?>> entityClassList = ReflectUtils.getClassListByAnnotation(getAttribute(AttributeKey.ENTITY_PACKAGE, String.class), Entity.class);
7778

7879
List<EntityInfo> entityInfos = entityClassList.stream().map(EntityInfo::buildFromEntity)
7980
.filter(Objects::nonNull)
8081
.collect(Collectors.toList());
8182

82-
setAttribute("entityInfos", entityInfos);
83+
setAttribute(AttributeKey.ENTITY_INFOS, entityInfos);
8384
}
8485

8586
}

src/main/java/io/github/gcdd1993/entity/Permission.java renamed to src/main/java/io/github/gcdd1993/jpa/autogen/entity/Permission.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.gcdd1993.entity;
1+
package io.github.gcdd1993.jpa.autogen.entity;
22

33
import lombok.Data;
44

src/main/java/io/github/gcdd1993/entity/Role.java renamed to src/main/java/io/github/gcdd1993/jpa/autogen/entity/Role.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.gcdd1993.entity;
1+
package io.github.gcdd1993.jpa.autogen.entity;
22

33
import lombok.Data;
44

src/main/java/io/github/gcdd1993/entity/User.java renamed to src/main/java/io/github/gcdd1993/jpa/autogen/entity/User.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.gcdd1993.entity;
1+
package io.github.gcdd1993.jpa.autogen.entity;
22

33
import lombok.Data;
44

src/main/java/io/github/gcdd1993/generator/BaseCodeGenerator.java renamed to src/main/java/io/github/gcdd1993/jpa/autogen/generator/BaseCodeGenerator.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package io.github.gcdd1993.generator;
1+
package io.github.gcdd1993.jpa.autogen.generator;
22

33
import freemarker.template.Configuration;
44
import freemarker.template.Template;
55
import freemarker.template.TemplateException;
6-
import io.github.gcdd1993.constant.AttributeKey;
7-
import io.github.gcdd1993.constant.TemplateKey;
8-
import io.github.gcdd1993.context.ApplicationContext;
9-
import io.github.gcdd1993.model.EntityInfo;
6+
import io.github.gcdd1993.jpa.autogen.constant.AttributeKey;
7+
import io.github.gcdd1993.jpa.autogen.constant.TemplateKey;
8+
import io.github.gcdd1993.jpa.autogen.context.ApplicationContext;
9+
import io.github.gcdd1993.jpa.autogen.model.EntityInfo;
1010

1111
import java.io.File;
1212
import java.io.FileWriter;
@@ -33,8 +33,6 @@ public abstract class BaseCodeGenerator implements ICodeGenerator {
3333

3434
public BaseCodeGenerator(ApplicationContext applicationContext) {
3535
this.applicationContext = applicationContext;
36-
37-
this.applicationContext.setAttribute(AttributeKey.TEMPLATE_PATH, applicationContext.getAttribute("template.basePath"));
3836
}
3937

4038

@@ -81,17 +79,16 @@ public void generate(EntityInfo entityInfo) {
8179

8280
// imports
8381
String idClassPackage = entityInfo.getIdClass().getPackage().getName();
84-
String importIgnorePackage = applicationContext.getAttribute("import.ignore.package");
82+
String importIgnorePackage = applicationContext.getAttribute(AttributeKey.IMPORT_IGNORE_PACKAGE);
8583

86-
if (!importIgnorePackage.contains(idClassPackage) && !applicationContext.getAttribute("entity.package").equals(idClassPackage)) {
84+
if (!importIgnorePackage.contains(idClassPackage) && !applicationContext.getAttribute(AttributeKey.ENTITY_PACKAGE).equals(idClassPackage)) {
8785
params.put(TemplateKey.IMPORTS, Collections.singletonList(entityInfo.getIdClass().getName()));
8886
}
8987

9088
beforeGenerate();
9189

9290
// put all attributes into params
93-
applicationContext.getAttributes()
94-
.forEach((k, v) -> params.put(k.replace(".", "_"), v));
91+
applicationContext.getAttributes().forEach(params::put);
9592

9693
File file = checkFile();
9794
if (file == null) {

src/main/java/io/github/gcdd1993/generator/ICodeGenerator.java renamed to src/main/java/io/github/gcdd1993/jpa/autogen/generator/ICodeGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.gcdd1993.generator;
1+
package io.github.gcdd1993.jpa.autogen.generator;
22

33
/**
44
* TODO

src/main/java/io/github/gcdd1993/generator/RepositoryCodeGenerator.java renamed to src/main/java/io/github/gcdd1993/jpa/autogen/generator/RepositoryCodeGenerator.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package io.github.gcdd1993.generator;
1+
package io.github.gcdd1993.jpa.autogen.generator;
22

3-
import io.github.gcdd1993.constant.AttributeKey;
4-
import io.github.gcdd1993.context.ApplicationContext;
5-
import io.github.gcdd1993.model.EntityInfo;
3+
import io.github.gcdd1993.jpa.autogen.constant.AttributeKey;
4+
import io.github.gcdd1993.jpa.autogen.context.ApplicationContext;
5+
import io.github.gcdd1993.jpa.autogen.model.EntityInfo;
66

77
/**
88
* Repository 代码生成器
@@ -12,6 +12,8 @@
1212
*/
1313
public class RepositoryCodeGenerator extends BaseCodeGenerator {
1414

15+
private static final String DEFAULT_PACKAGE_NAME_SUFFIX = ".service";
16+
1517
public RepositoryCodeGenerator(ApplicationContext applicationContext) {
1618
super(applicationContext);
1719
}
@@ -20,12 +22,12 @@ public RepositoryCodeGenerator(ApplicationContext applicationContext) {
2022
public void beforeGenerate() {
2123
EntityInfo entityInfo = applicationContext.getAttribute(AttributeKey.ENTITY_INFO, EntityInfo.class);
2224

23-
String packageName = applicationContext.getOrDefaultAttribute("repository.package", entityInfo.getPackageName() + ".repository", String.class);
25+
String packageName = applicationContext.getOrDefaultAttribute(AttributeKey.REPOSITORY_PACKAGE, entityInfo.getPackageName() + DEFAULT_PACKAGE_NAME_SUFFIX, String.class);
2426
applicationContext.setAttribute(AttributeKey.PACKAGE_NAME, packageName);
2527

2628
// targetFileName
27-
applicationContext.setAttribute(AttributeKey.TARGET_CLASS_NAME, entityInfo.getSimpleName() + applicationContext.getAttribute("repository.suffix"));
28-
applicationContext.setAttribute(AttributeKey.TEMPLATE_NAME, applicationContext.getAttribute("repository.template"));
29+
applicationContext.setAttribute(AttributeKey.TARGET_CLASS_NAME, entityInfo.getSimpleName() + applicationContext.getAttribute(AttributeKey.REPOSITORY_SUFFIX));
30+
applicationContext.setAttribute(AttributeKey.TEMPLATE_NAME, applicationContext.getAttribute(AttributeKey.REPOSITORY_TEMPLATE));
2931

3032
}
3133

0 commit comments

Comments
 (0)