diff --git a/docs/zh/db-row.md b/docs/zh/db-row.md index 9414e116..9e64cf26 100644 --- a/docs/zh/db-row.md +++ b/docs/zh/db-row.md @@ -49,6 +49,9 @@ Row row = Db.selectOneBySql("select * from ...."); Account entity = row.toEntity(Account.class); ``` +需要注意的是,当我们进行 join 关联查询时,返回的结果如果出现重复字段,Row 会自动添加上 字段序号。 + + ## Row.toObject() `Row.toObject(Other.class)` 和 `Row.toEntity(Entity.class)` 和相似。不一样的地方在于 `Row.toObject(Other.class)` 是通过去查找 diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/Generator.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/Generator.java index b6abb05e..c6b8fb61 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/Generator.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/Generator.java @@ -80,6 +80,7 @@ public class Generator { File mapperJavaFile = new File(globalConfig.getSourceDir(), mapperPackagePath + "/" + table.buildMapperClassName() + ".java"); + if (!mapperJavaFile.getParentFile().exists()) { if (!mapperJavaFile.getParentFile().mkdirs()) { throw new IllegalStateException("Can not mkdirs by dir: " + mapperJavaFile.getParentFile()); diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java index b54eb846..614e5746 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java @@ -103,6 +103,19 @@ public class Column { return "set" + StringUtil.firstCharToUpperCase(property); } + + public String buildRemarks(){ + if (StringUtil.isBlank(remarks)){ + return ""; + }else { + StringBuilder sb = new StringBuilder("/**\n") + .append(" * ").append(remarks).append("\n") + .append(" */"); + return sb.toString(); + } + } + + public String buildPropertyName() { String entityJavaFileName = name; return StringUtil.firstCharToLowerCase(StringUtil.underlineToCamel(entityJavaFileName)); diff --git a/mybatis-flex-codegen/src/main/resources/templates/enjoy/entity.tpl b/mybatis-flex-codegen/src/main/resources/templates/enjoy/entity.tpl index bf6de06f..2816dd43 100644 --- a/mybatis-flex-codegen/src/main/resources/templates/enjoy/entity.tpl +++ b/mybatis-flex-codegen/src/main/resources/templates/enjoy/entity.tpl @@ -9,6 +9,7 @@ import #(importClass); public class #(table.buildEntityClassName())#(table.buildExtends())#(table.buildImplements()) { #for(column: table.columns) + #(column.buildRemarks()) #(column.buildAnnotations())private #(column.propertySimpleType) #(column.property); #end