commit 51a4ff5054a2aae5da4f5d997b9fcf4d85670a85 Author: ZhouXY108 Date: Mon Jan 16 11:05:46 2023 +0800 first commit. diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e112a70 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..7c03a53 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/bin/xyz/zhouxy/mappojo/generator/App.class b/bin/xyz/zhouxy/mappojo/generator/App.class new file mode 100644 index 0000000..c77ae92 Binary files /dev/null and b/bin/xyz/zhouxy/mappojo/generator/App.class differ diff --git a/bin/xyz/zhouxy/mappojo/generator/FieldTypeMap.class b/bin/xyz/zhouxy/mappojo/generator/FieldTypeMap.class new file mode 100644 index 0000000..be7e2a6 Binary files /dev/null and b/bin/xyz/zhouxy/mappojo/generator/FieldTypeMap.class differ diff --git a/bin/xyz/zhouxy/plusone/system/domain/model/role/Role.class b/bin/xyz/zhouxy/plusone/system/domain/model/role/Role.class new file mode 100644 index 0000000..218b83f Binary files /dev/null and b/bin/xyz/zhouxy/plusone/system/domain/model/role/Role.class differ diff --git a/src/xyz/zhouxy/mappojo/generator/App.java b/src/xyz/zhouxy/mappojo/generator/App.java new file mode 100644 index 0000000..15775cd --- /dev/null +++ b/src/xyz/zhouxy/mappojo/generator/App.java @@ -0,0 +1,112 @@ +package xyz.zhouxy.mappojo.generator; + +import java.util.LinkedHashMap; +import java.util.Map; + +public class App { + + public static void main(String[] args) { + boolean chain = true; + String packageName = "xyz.zhouxy.plusone.system.domain.model.role"; + String className = "Role"; + FieldTypeMap fieldTypeMap = new FieldTypeMap() + .addField("id", "Long") + .addField("name", "String") + .addField("identifier", "String") + .addField("status", "Integer") + .addField("remarks", "String") + .addField("create_time", "LocalDateTime") + .addField("created_by", "Long") + .addField("update_time", "LocalDateTime") + .addField("updated_by", "Long") + .addField("version", "Long") + ; + + Map fields = fieldTypeMap.fields; + StringBuilder result = new StringBuilder(String.format(""" + package %s; + + import java.util.*; + + public class %s { + + private final String[] fieldNames = { "%s" }; + """, packageName, className, String.join("\", \"", fields.keySet()))); + + result.append(String.format(""" + + private final Map fields; + + public %s() { + this.fields = new HashMap<>(); + } + + public %s(final Map fields) { + this.fields = fields; + } + """, className, className)); + + for (var field_name : fields.keySet()) { + var words = field_name.split("_"); + StringBuilder fieldName = new StringBuilder(); + StringBuilder FieldName = new StringBuilder(); + + for (int i = 0; i < words.length; i++) { + var word = words[i]; + var Word = word.substring(0, 1).toUpperCase() + word.substring(1); + fieldName.append((i == 0) ? word : Word); + FieldName.append(Word); + } + + String fieldNameStr = fieldName.toString(); + String FieldNameStr = FieldName.toString(); + + String fieldTypeName = fields.get(field_name); + result.append(String.format(""" + + public %s get%s() { + return (%s) this.fields.get("%s"); + } + """, fieldTypeName, FieldNameStr, fieldTypeName, field_name)); + if (chain) { + result.append(String.format(""" + public %s set%s(%s %s) { + this.fields.put("%s", %s); + return this; + } + """, className, FieldNameStr, fieldTypeName, fieldNameStr, field_name, fieldNameStr)); + } else { + result.append(String.format(""" + public void set%s(%s %s) { + this.fields.put("%s", %s); + } + """, FieldNameStr, fieldTypeName, fieldNameStr, field_name, fieldNameStr)); + } + } + + result.append(""" + + @Override + public String toString() { + return this.fields.toString(); + } + """); + result.append("}\n"); + String resultStr = result.toString(); + System.out.println(resultStr); + } +} + +class FieldTypeMap { + final Map fields = new LinkedHashMap<>(); + + FieldTypeMap addField(String field_name, String type) { + this.fields.put(field_name, type); + return this; + } + + FieldTypeMap addField(String field_name, Class type) { + this.fields.put(field_name, type.getSimpleName()); + return this; + } +} diff --git a/src/xyz/zhouxy/plusone/system/domain/model/role/Role.java b/src/xyz/zhouxy/plusone/system/domain/model/role/Role.java new file mode 100644 index 0000000..2192d71 --- /dev/null +++ b/src/xyz/zhouxy/plusone/system/domain/model/role/Role.java @@ -0,0 +1,129 @@ +package xyz.zhouxy.plusone.system.domain.model.role; + +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.Map; + +public class Role { + + private final String[] fieldNames = { "id", "name", "identifier", "status", "remarks", + "create_time", "created_by", "update_time", "updated_by", "version" }; + + private final Map fields; + + public Role() { + this.fields = new HashMap<>(); + } + + public Role(final Map fields) { + this.fields = fields; + } + + public Long getId() { + return (Long) this.fields.get("id"); + } + + public Role setId(Long id) { + this.fields.put("id", id); + return this; + } + + public String getName() { + return (String) this.fields.get("name"); + } + + public Role setName(String name) { + this.fields.put("name", name); + return this; + } + + public String getIdentifier() { + return (String) this.fields.get("identifier"); + } + + public Role setIdentifier(String identifier) { + this.fields.put("identifier", identifier); + return this; + } + + public Integer getStatus() { + return (Integer) this.fields.get("status"); + } + + public Role setStatus(Integer status) { + this.fields.put("status", status); + return this; + } + + public String getRemarks() { + return (String) this.fields.get("remarks"); + } + + public Role setRemarks(String remarks) { + this.fields.put("remarks", remarks); + return this; + } + + public LocalDateTime getCreateTime() { + return (LocalDateTime) this.fields.get("create_time"); + } + + public Role setCreateTime(LocalDateTime createTime) { + this.fields.put("create_time", createTime); + return this; + } + + public Long getCreatedBy() { + return (Long) this.fields.get("created_by"); + } + + public Role setCreatedBy(Long createdBy) { + this.fields.put("created_by", createdBy); + return this; + } + + public LocalDateTime getUpdateTime() { + return (LocalDateTime) this.fields.get("update_time"); + } + + public Role setUpdateTime(LocalDateTime updateTime) { + this.fields.put("update_time", updateTime); + return this; + } + + public Long getUpdatedBy() { + return (Long) this.fields.get("updated_by"); + } + + public Role setUpdatedBy(Long updatedBy) { + this.fields.put("updated_by", updatedBy); + return this; + } + + public Long getVersion() { + return (Long) this.fields.get("version"); + } + + public Role setVersion(Long version) { + this.fields.put("version", version); + return this; + } + + @Override + public String toString() { + return this.fields.toString(); + } + + public static void main(String[] args) { + Role role = new Role() + .setId(2333L) + .setIdentifier("role") + .setName("角色") + .setStatus(0) + .setCreateTime(LocalDateTime.of(2000, 1, 29, 5, 20, 8)) + .setCreatedBy(666L) + .setUpdatedBy(999L) + .setUpdateTime(LocalDateTime.now()); + System.out.println(role); + } +}