first commit.
This commit is contained in:
commit
51a4ff5054
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin",
|
||||
"java.project.referencedLibraries": [
|
||||
"lib/**/*.jar"
|
||||
]
|
||||
}
|
18
README.md
Normal file
18
README.md
Normal file
@ -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).
|
BIN
bin/xyz/zhouxy/mappojo/generator/App.class
Normal file
BIN
bin/xyz/zhouxy/mappojo/generator/App.class
Normal file
Binary file not shown.
BIN
bin/xyz/zhouxy/mappojo/generator/FieldTypeMap.class
Normal file
BIN
bin/xyz/zhouxy/mappojo/generator/FieldTypeMap.class
Normal file
Binary file not shown.
BIN
bin/xyz/zhouxy/plusone/system/domain/model/role/Role.class
Normal file
BIN
bin/xyz/zhouxy/plusone/system/domain/model/role/Role.class
Normal file
Binary file not shown.
112
src/xyz/zhouxy/mappojo/generator/App.java
Normal file
112
src/xyz/zhouxy/mappojo/generator/App.java
Normal file
@ -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<String, String> 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<String, Object> fields;
|
||||
|
||||
public %s() {
|
||||
this.fields = new HashMap<>();
|
||||
}
|
||||
|
||||
public %s(final Map<String, Object> 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<String, String> 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;
|
||||
}
|
||||
}
|
129
src/xyz/zhouxy/plusone/system/domain/model/role/Role.java
Normal file
129
src/xyz/zhouxy/plusone/system/domain/model/role/Role.java
Normal file
@ -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<String, Object> fields;
|
||||
|
||||
public Role() {
|
||||
this.fields = new HashMap<>();
|
||||
}
|
||||
|
||||
public Role(final Map<String, Object> 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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user