tanghc 4 years ago
parent
commit
f26c294a3b
24 changed files with 1160 additions and 450 deletions
  1. 90 0
      front/public/velocity/csharp.json
  2. 114 0
      front/public/velocity/java.json
  3. 11 0
      front/src/utils/global.js
  4. 28 82
      front/src/views/template/edit.vue
  5. 99 105
      gen/src/main/java/com/gitee/gen/gen/ColumnDefinition.java
  6. 26 0
      gen/src/main/java/com/gitee/gen/gen/CsharpColumnDefinition.java
  7. 79 0
      gen/src/main/java/com/gitee/gen/gen/JavaColumnDefinition.java
  8. 98 90
      gen/src/main/java/com/gitee/gen/gen/SQLContext.java
  9. 135 93
      gen/src/main/java/com/gitee/gen/gen/TableDefinition.java
  10. 15 2
      gen/src/main/java/com/gitee/gen/gen/TableSelector.java
  11. 43 0
      gen/src/main/java/com/gitee/gen/gen/TypeEnum.java
  12. 75 0
      gen/src/main/java/com/gitee/gen/gen/TypeFormatter.java
  13. 22 0
      gen/src/main/java/com/gitee/gen/gen/converter/ColumnTypeConverter.java
  14. 39 0
      gen/src/main/java/com/gitee/gen/gen/converter/CsharpColumnTypeConverter.java
  15. 52 0
      gen/src/main/java/com/gitee/gen/gen/converter/JavaColumnTypeConverter.java
  16. 7 17
      gen/src/main/java/com/gitee/gen/gen/mysql/MySqlColumnSelector.java
  17. 72 0
      gen/src/main/java/com/gitee/gen/gen/mysql/MySqlTypeFormatter.java
  18. 6 21
      gen/src/main/java/com/gitee/gen/gen/oracle/OracleColumnSelector.java
  19. 72 0
      gen/src/main/java/com/gitee/gen/gen/oracle/OracleTypeFormatter.java
  20. 3 20
      gen/src/main/java/com/gitee/gen/gen/postgresql/PostgreSqlColumnSelector.java
  21. 72 0
      gen/src/main/java/com/gitee/gen/gen/postgresql/PostgreSqlTypeFormatter.java
  22. 1 0
      gen/src/main/java/com/gitee/gen/service/GeneratorService.java
  23. 0 20
      gen/src/main/java/com/gitee/gen/util/DateUtil.java
  24. 1 0
      gen/src/main/java/com/gitee/gen/util/SqlTypeUtil.java

+ 90 - 0
front/public/velocity/csharp.json

@@ -0,0 +1,90 @@
+{
+  "data": [
+    {
+      "expression": "${pk}",
+      "text": "主键对象,同${column}"
+    },
+    {
+      "expression": "${context}",
+      "text": "",
+      "children": [
+        {
+          "expression": "${context.dbName}",
+          "text": "数据库名"
+        },
+        {
+          "expression": "${context.className}",
+          "text": "类名"
+        },
+        {
+          "expression": "${context.packageName}",
+          "text": "namespace"
+        },
+        {
+          "expression": "${context.pkName}",
+          "text": "表主键名"
+        }
+      ]
+    },
+    {
+      "expression": "${table}",
+      "text": "",
+      "children": [
+        {
+          "expression": "${table.tableName}",
+          "text": "数据库表名"
+        },
+        {
+          "expression": "${table.comment}",
+          "text": "表注释"
+        }
+      ]
+    },
+    {
+      "expression": "#foreach($column in $csharpColumns) #end",
+      "text": "",
+      "children": [
+        {
+          "expression": "${velocityCount}",
+          "text": "foreach循环下标,从1开始"
+        },
+        {
+          "expression": "${column.columnName}",
+          "text": "表中字段名"
+        },
+        {
+          "expression": "${column.type}",
+          "text": "字段的数据库类型"
+        },
+        {
+          "expression": "${column.field}",
+          "text": "字段名"
+        },
+        {
+          "expression": "${column.property}",
+          "text": "属性名"
+        },
+        {
+          "expression": "${column.fieldType}",
+          "text": "字段类型"
+        },
+        {
+          "expression": "${column.isIdentity}",
+          "text": "是否自增,返回boolean"
+        },
+        {
+          "expression": "${column.isPk}",
+          "text": "是否主键,返回boolean"
+        },
+        {
+          "expression": "${column.isIdentityPk}",
+          "text": "是否自增主键,返回boolean"
+        },
+        {
+          "expression": "${column.comment}",
+          "text": "字段注释"
+        }
+      ]
+    }
+  ]
+}

+ 114 - 0
front/public/velocity/java.json

@@ -0,0 +1,114 @@
+{
+  "data": [
+    {
+      "expression": "${pk}",
+      "text": "主键对象,同${column}"
+    },
+    {
+      "expression": "${context}",
+      "text": "",
+      "children": [
+        {
+          "expression": "${context.dbName}",
+          "text": "数据库名"
+        },
+        {
+          "expression": "${context.packageName}",
+          "text": "包名"
+        },
+        {
+          "expression": "${context.javaBeanName}",
+          "text": "Java类名"
+        },
+        {
+          "expression": "${context.javaBeanNameLF}",
+          "text": "Java类名且首字母小写"
+        },
+        {
+          "expression": "${context.pkName}",
+          "text": "表主键名"
+        },
+        {
+          "expression": "${context.javaPkName}",
+          "text": "表主键对应的java字段名"
+        },
+        {
+          "expression": "${context.javaPkType}",
+          "text": "主键的java类型"
+        },
+        {
+          "expression": "${context.mybatisPkType}",
+          "text": "主键对应的mybatis类型"
+        }
+      ]
+    },
+    {
+      "expression": "${table}",
+      "text": "",
+      "children": [
+        {
+          "expression": "${table.tableName}",
+          "text": "数据库表名"
+        },
+        {
+          "expression": "${table.comment}",
+          "text": "表注释"
+        }
+      ]
+    },
+    {
+      "expression": "#foreach($column in $columns) #end",
+      "text": "",
+      "children": [
+        {
+          "expression": "${velocityCount}",
+          "text": "foreach循环下标,从1开始"
+        },
+        {
+          "expression": "${column.columnName}",
+          "text": "表中字段名"
+        },
+        {
+          "expression": "${column.type}",
+          "text": "字段的数据库类型"
+        },
+        {
+          "expression": "${column.javaFieldName}",
+          "text": "java字段名"
+        },
+        {
+          "expression": "${column.javaFieldNameUF}",
+          "text": "java字段名首字母大写"
+        },
+        {
+          "expression": "${column.javaType}",
+          "text": "字段的java类型"
+        },
+        {
+          "expression": "${column.javaTypeBox}",
+          "text": "字段的java装箱类型,如Integer"
+        },
+        {
+          "expression": "${column.isIdentity}",
+          "text": "是否自增,返回boolean"
+        },
+        {
+          "expression": "${column.isPk}",
+          "text": "是否主键,返回boolean"
+        },
+        {
+          "expression": "${column.isIdentityPk}",
+          "text": "是否自增主键,返回boolean"
+        },
+        {
+          "expression": "${column.mybatisJdbcType}",
+          "text": "mybatis定义的jdbcType"
+        },
+        {
+          "expression": "${column.comment}",
+          "text": "字段注释"
+        }
+      ]
+    }
+  ]
+}

+ 11 - 0
front/src/utils/global.js

@@ -112,6 +112,17 @@ Object.assign(Vue.prototype, {
       this.clipboard.destroy()
     }
   },
+  /**
+   *  文件必须放在public下面
+   * @param path 相对于public文件夹路径,如文件在public/static/sign.md,填:static/sign.md
+   * @param callback 回调函数,函数参数是文件内容
+   */
+  getFile: function(path, callback) {
+    axios.get(path)
+      .then(function(response) {
+        callback.call(this, response.data)
+      })
+  },
   downloadText(filename, text) {
     const element = document.createElement('a')
     element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text))

+ 28 - 82
front/src/views/template/edit.vue

@@ -33,6 +33,9 @@
         <p class="velocity-tip">
           点击变量直接插入
         </p>
+        <el-tabs v-model="activeName" type="card" @tab-click="onTabClick">
+          <el-tab-pane v-for="item in velocityConfig" :key="item.name" :label="item.label" :name="item.name" :content="item" />
+        </el-tabs>
         <div v-for="item in treeData" :key="item.expression" class="velocity-var">
           <div v-if="!item.children">
             <li>
@@ -111,88 +114,9 @@ export default {
       },
       isVelocityBarFixed: false,
       // tree
-      treeData: [{
-        expression: '${pk}',
-        text: '主键对象,同${column}'
-      }, {
-        expression: '${context}',
-        text: '',
-        children: [{
-          expression: '${context.dbName}',
-          text: '数据库名'
-        }, {
-          expression: '${context.packageName}',
-          text: '包名'
-        }, {
-          expression: '${context.javaBeanName}',
-          text: 'Java类名'
-        }, {
-          expression: '${context.javaBeanNameLF}',
-          text: 'Java类名且首字母小写'
-        }, {
-          expression: '${context.pkName}',
-          text: '表主键名'
-        }, {
-          expression: '${context.javaPkName}',
-          text: '表主键对应的java字段名'
-        }, {
-          expression: '${context.javaPkType}',
-          text: '主键的java类型'
-        }, {
-          expression: '${context.mybatisPkType}',
-          text: '主键对应的mybatis类型'
-        }]
-      }, {
-        expression: '${table}',
-        text: '',
-        children: [{
-          expression: '${table.tableName}',
-          text: '数据库表名'
-        }, {
-          expression: '${table.comment}',
-          text: '表注释'
-        }]
-      }, {
-        expression: '#foreach($column in $columns) #end',
-        text: '',
-        children: [{
-          expression: '${velocityCount}',
-          text: 'foreach循环下标,从1开始'
-        }, {
-          expression: '${column.columnName}',
-          text: '表中字段名'
-        }, {
-          expression: '${column.type}',
-          text: '字段的数据库类型'
-        }, {
-          expression: '${column.javaFieldName}',
-          text: 'java字段名'
-        }, {
-          expression: '${column.javaFieldNameUF}',
-          text: 'java字段名首字母大写'
-        }, {
-          expression: '${column.javaType}',
-          text: '字段的java类型'
-        }, {
-          expression: '${column.javaTypeBox}',
-          text: '字段的java装箱类型,如Integer'
-        }, {
-          expression: '${column.isIdentity}',
-          text: '是否自增,返回boolean'
-        }, {
-          expression: '${column.isPk}',
-          text: '是否主键,返回boolean'
-        }, {
-          expression: '${column.isIdentityPk}',
-          text: '是否自增主键,返回boolean'
-        }, {
-          expression: '${column.mybatisJdbcType}',
-          text: 'mybatis定义的jdbcType'
-        }, {
-          expression: '${column.comment}',
-          text: '字段注释'
-        }]
-      }],
+      activeName: 'java',
+      treeData: [],
+      velocityConfig: [],
       defaultProps: {
         children: 'children',
         label: 'text'
@@ -206,8 +130,26 @@ export default {
         this.formData = resp.data
       })
     }
+    this.loadVelocityVar()
   },
   methods: {
+    loadVelocityVar() {
+      this.getFile(`velocity/java.json?q=${new Date().getTime()}`, content => {
+        this.velocityConfig.push({
+          name: 'java',
+          label: 'Java变量',
+          data: content.data
+        })
+        this.treeData = content.data
+      })
+      this.getFile(`velocity/csharp.json?q=${new Date().getTime()}`, content => {
+        this.velocityConfig.push({
+          name: 'csharp',
+          label: 'C#变量',
+          data: content.data
+        })
+      })
+    },
     onExpressionClick(exp) {
       const codemirror = this.$refs.editor.codemirror
       // 插入表达式
@@ -228,6 +170,10 @@ export default {
           })
         }
       })
+    },
+    onTabClick(tab) {
+      const item = tab.$attrs.content
+      this.treeData = item.data
     }
   }
 }

+ 99 - 105
gen/src/main/java/com/gitee/gen/gen/ColumnDefinition.java

@@ -1,113 +1,107 @@
 package com.gitee.gen.gen;
 
-import com.gitee.gen.util.FieldUtil;
-import com.gitee.gen.util.SqlTypeUtil;
+import com.gitee.gen.gen.converter.ColumnTypeConverter;
 
 /**
  * 表字段信息
  */
-public class ColumnDefinition  {
-
-	private String columnName; // 数据库字段名
-	private String type; // 数据库类型
-	private boolean isIdentity; // 是否自增
-	private boolean isPk; // 是否主键
-	private String comment; // 字段注释
-
-	/**
-	 * 是否是自增主键
-	 * 
-	 * @return
-	 */
-	public boolean getIsIdentityPk() {
-		return isPk && isIdentity;
-	}
-	
-	/**
-	 * 返回java字段名,并且第一个字母大写
-	 * 
-	 * @return
-	 */
-	public String getJavaFieldNameUF() {
-		return FieldUtil.upperFirstLetter(getJavaFieldName());
-	}
-	
-	/**
-	 * 返回java字段
-	 * @return
-	 */
-	public String getJavaFieldName() {
-		return FieldUtil.underlineFilter(columnName);
-	}
-	
-	/**
-	 * 获得基本类型,int,float
-	 * @return
-	 */
-	
-	public String getJavaType() {
-		String typeLower = type.toLowerCase();
-		return SqlTypeUtil.convertToJavaType(typeLower);
-	}
-	
-	/**
-	 * 获得装箱类型,Integer,Float
-	 * @return
-	 */
-	
-	public String getJavaTypeBox(){
-		String typeLower = type.toLowerCase();
-		return SqlTypeUtil.convertToJavaBoxType(typeLower);
-	}
-	
-	public String getMybatisJdbcType() {
-		String typeLower = type.toLowerCase();
-		return SqlTypeUtil.convertToMyBatisJdbcType(typeLower);
-	}
-
-	public String getColumnName() {
-		return columnName;
-	}
-
-	public void setColumnName(String columnName) {
-		this.columnName = columnName;
-	}
-
-	public String getType() {
-		return type;
-	}
-
-	public void setType(String type) {
-		this.type = type;
-	}
-
-	public boolean getIsIdentity() {
-		return isIdentity;
-	}
-
-	public void setIsIdentity(boolean isIdentity) {
-		this.isIdentity = isIdentity;
-	}
-
-	public boolean getIsPk() {
-		return isPk;
-	}
-
-	public void setIsPk(boolean isPk) {
-		this.isPk = isPk;
-	}
-
-	public String getComment() {
-		return comment;
-	}
-
-	public void setComment(String comment) {
-		if(comment == null) {
-			comment = "";
-		}
-		this.comment = comment;
-	}
-	
-	
+public class ColumnDefinition {
 
+    /**
+     * 数据库字段名
+     */
+    private String columnName;
+    /**
+     * 数据库类型
+     */
+    private String type;
+    /**
+     * 是否自增
+     */
+    private Boolean isIdentity;
+    /**
+     * 是否主键
+     */
+    private Boolean isPk;
+    /**
+     * 字段注释
+     */
+    private String comment;
+
+    /**
+     * 获得基本类型,int,float
+     *
+     * @return 返回基本类型
+     */
+
+    public String getFieldType() {
+        return getColumnTypeConverter().convertType(type);
+    }
+
+    /**
+     * 获得装箱类型,Integer,Float
+     *
+     * @return 返回装箱类型
+     */
+
+    public String getFieldTypeBox() {
+        return getColumnTypeConverter().convertTypeBox(getType());
+    }
+
+    /**
+     * 是否是自增主键
+     *
+     * @return true, 是自增主键
+     */
+    public boolean getIsIdentityPk() {
+        return getIsPk() && getIsIdentity();
+    }
+
+    public String getColumnName() {
+        return columnName;
+    }
+
+    public void setColumnName(String columnName) {
+        this.columnName = columnName;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public Boolean getIsIdentity() {
+        return isIdentity;
+    }
+
+    public void setIsIdentity(Boolean isIdentity) {
+        this.isIdentity = isIdentity;
+    }
+
+    public Boolean getIsPk() {
+        return isPk;
+    }
+
+    public void setIsPk(Boolean isPk) {
+        this.isPk = isPk;
+    }
+
+
+    public String getComment() {
+        return comment;
+    }
+
+    public void setComment(String comment) {
+        if (comment == null) {
+            comment = "";
+        }
+        this.comment = comment;
+    }
+
+    public ColumnTypeConverter getColumnTypeConverter() {
+        throw new UnsupportedOperationException("未覆盖com.gitee.gen.gen.ColumnDefinition.getColumnTypeConverter方法");
+    }
 }

+ 26 - 0
gen/src/main/java/com/gitee/gen/gen/CsharpColumnDefinition.java

@@ -0,0 +1,26 @@
+package com.gitee.gen.gen;
+
+import com.gitee.gen.gen.converter.ColumnTypeConverter;
+import com.gitee.gen.gen.converter.CsharpColumnTypeConverter;
+import com.gitee.gen.util.FieldUtil;
+
+/**
+ * @author tanghc
+ */
+public class CsharpColumnDefinition extends ColumnDefinition {
+
+    private static final ColumnTypeConverter COLUMN_TYPE_CONVERTER = new CsharpColumnTypeConverter();
+
+    public String getField() {
+        return FieldUtil.underlineFilter(getColumnName());
+    }
+
+    public String getProperty() {
+        return FieldUtil.upperFirstLetter(getField());
+    }
+
+    @Override
+    public ColumnTypeConverter getColumnTypeConverter() {
+        return COLUMN_TYPE_CONVERTER;
+    }
+}

+ 79 - 0
gen/src/main/java/com/gitee/gen/gen/JavaColumnDefinition.java

@@ -0,0 +1,79 @@
+package com.gitee.gen.gen;
+
+import com.gitee.gen.gen.converter.ColumnTypeConverter;
+import com.gitee.gen.gen.converter.JavaColumnTypeConverter;
+import com.gitee.gen.util.FieldUtil;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author tanghc
+ */
+public class JavaColumnDefinition extends ColumnDefinition {
+
+    private static final JavaColumnTypeConverter COLUMN_TYPE_CONVERTER = new JavaColumnTypeConverter();
+
+    private static final Map<String, String> TYPE_MYBATIS_MAP = new HashMap<>(64);
+    static {
+        TYPE_MYBATIS_MAP.put(TypeEnum.BIT.getType(), "BOOLEAN");
+        TYPE_MYBATIS_MAP.put(TypeEnum.BOOLEAN.getType(), "BOOLEAN");
+        TYPE_MYBATIS_MAP.put(TypeEnum.TINYINT.getType(), "TINYINT");
+        TYPE_MYBATIS_MAP.put(TypeEnum.SMALLINT.getType(), "INTEGER");
+        TYPE_MYBATIS_MAP.put(TypeEnum.INT.getType(), "INTEGER");
+        TYPE_MYBATIS_MAP.put(TypeEnum.BIGINT.getType(), "LONG");
+        TYPE_MYBATIS_MAP.put(TypeEnum.FLOAT.getType(), "FLOAT");
+        TYPE_MYBATIS_MAP.put(TypeEnum.DOUBLE.getType(), "DOUBLE");
+        TYPE_MYBATIS_MAP.put(TypeEnum.DECIMAL.getType(), "DECIMAL");
+        TYPE_MYBATIS_MAP.put(TypeEnum.VARCHAR.getType(), "VARCHAR");
+        TYPE_MYBATIS_MAP.put(TypeEnum.DATETIME.getType(), "TIMESTAMP");
+        TYPE_MYBATIS_MAP.put(TypeEnum.BLOB.getType(), "BLOB");
+    }
+
+    public String getMybatisJdbcType() {
+        return TYPE_MYBATIS_MAP.getOrDefault(getType(), "VARCHAR");
+    }
+
+    /**
+     * 返回java字段名,并且第一个字母大写
+     *
+     * @return 返回字段名
+     */
+    public String getJavaFieldNameUF() {
+        return FieldUtil.upperFirstLetter(getJavaFieldName());
+    }
+
+    /**
+     * 返回java字段
+     *
+     * @return 返回java字段
+     */
+    public String getJavaFieldName() {
+        return FieldUtil.underlineFilter(getColumnName());
+    }
+
+    /**
+     * 获得基本类型,int,float
+     *
+     * @return 返回基本类型
+     */
+
+    public String getJavaType() {
+        return getFieldType();
+    }
+
+    /**
+     * 获得装箱类型,Integer,Float
+     *
+     * @return 返回装箱类型
+     */
+
+    public String getJavaTypeBox() {
+        return getFieldTypeBox();
+    }
+
+    @Override
+    public ColumnTypeConverter getColumnTypeConverter() {
+        return COLUMN_TYPE_CONVERTER;
+    }
+}

+ 98 - 90
gen/src/main/java/com/gitee/gen/gen/SQLContext.java

@@ -2,100 +2,108 @@ package com.gitee.gen.gen;
 
 import com.gitee.gen.util.FieldUtil;
 
-import java.util.List;
-
 /**
  * SQL上下文,这里可以取到表,字段信息<br>
  * 最终会把SQL上下文信息放到velocity中
  */
 public class SQLContext {
 
-	/** 表结构定义 */
-	private TableDefinition tableDefinition;
-	/** 包名 */
-	private String packageName;
-	/** 数据库名 */
-	private String dbName;
-
-	public SQLContext(TableDefinition tableDefinition){
-		this.tableDefinition = tableDefinition;
-		// 默认为全字母小写的类名
-		this.packageName = getJavaBeanName().toLowerCase();
-	}
-	
-	/**
-	 * 返回Java类名
-	 * @return
-	 */
-	public String getJavaBeanName(){
-		String tableName = getJavaBeanNameLF();
-		return FieldUtil.upperFirstLetter(tableName);
-	}
-	
-	/**
-	 * 返回Java类名且首字母小写
-	 * @return
-	 */
-	public String getJavaBeanNameLF(){
-		String tableName = tableDefinition.getTableName();
-		tableName = FieldUtil.underlineFilter(tableName);
-		tableName = FieldUtil.dotFilter(tableName);
-		return FieldUtil.lowerFirstLetter(tableName);
-	}
-	
-	public String getPkName(){
-		if(this.tableDefinition.getPkColumn() != null){
-			return this.tableDefinition.getPkColumn().getColumnName();
-		}
-		return "";
-	}
-	
-	public String getJavaPkName(){
-		if(this.tableDefinition.getPkColumn() != null){
-			return this.tableDefinition.getPkColumn().getJavaFieldName();
-		}
-		return "";
-	}
-	
-	public String getJavaPkType(){
-		if(this.tableDefinition.getPkColumn() != null){
-			return this.tableDefinition.getPkColumn().getJavaType();
-		}
-		return "";
-	}
-	
-	public String getMybatisPkType(){
-		if(this.tableDefinition.getPkColumn() != null){
-			return this.tableDefinition.getPkColumn().getMybatisJdbcType();
-		}
-		return "";
-	}
-
-	public TableDefinition getTableDefinition() {
-		return tableDefinition;
-	}
-
-	public void setTableDefinition(TableDefinition tableDefinition) {
-		this.tableDefinition = tableDefinition;
-	}
-	
-	public List<ColumnDefinition> getColumnDefinitionList(){
-		return tableDefinition.getColumnDefinitions();
-	}
-
-	public String getPackageName() {
-		return packageName;
-	}
-
-	public void setPackageName(String packageName) {
-		this.packageName = packageName;
-	}
-
-	public String getDbName() {
-		return dbName;
-	}
-
-	public void setDbName(String dbName) {
-		this.dbName = dbName;
-	}
+    /**
+     * 表结构定义
+     */
+    private final TableDefinition tableDefinition;
+    private final JavaColumnDefinition javaPkColumn;
+    /**
+     * 包名
+     */
+    private String packageName;
+    /**
+     * 数据库名
+     */
+    private String dbName;
+
+    public SQLContext(TableDefinition tableDefinition) {
+        this.tableDefinition = tableDefinition;
+        // 默认为全字母小写的类名
+        this.packageName = getJavaBeanName().toLowerCase();
+        this.javaPkColumn = (JavaColumnDefinition) this.tableDefinition.getPkColumn();
+    }
+
+    /**
+     * 返回Java类名
+     *
+     * @return
+     */
+    public String getJavaBeanName() {
+        return getClassName();
+    }
+
+    /**
+     * 返回类名
+     * @return
+     */
+    public String getClassName() {
+        String tableName = getJavaBeanNameLF();
+        return FieldUtil.upperFirstLetter(tableName);
+    }
+
+    /**
+     * 返回Java类名且首字母小写
+     *
+     * @return
+     */
+    public String getJavaBeanNameLF() {
+        String tableName = tableDefinition.getTableName();
+        tableName = FieldUtil.underlineFilter(tableName);
+        tableName = FieldUtil.dotFilter(tableName);
+        return FieldUtil.lowerFirstLetter(tableName);
+    }
+
+    public String getPkName() {
+        if (javaPkColumn != null) {
+            return javaPkColumn.getColumnName();
+        }
+        return "";
+    }
+
+    public String getJavaPkName() {
+        if (javaPkColumn != null) {
+            return javaPkColumn.getJavaFieldName();
+        }
+        return "";
+    }
+
+    public String getJavaPkType() {
+        if (javaPkColumn != null) {
+            return javaPkColumn.getJavaType();
+        }
+        return "";
+    }
+
+    public String getMybatisPkType() {
+        if (javaPkColumn != null) {
+            return javaPkColumn.getMybatisJdbcType();
+        }
+        return "";
+    }
+
+    public TableDefinition getTableDefinition() {
+        return tableDefinition;
+    }
+
+    public String getPackageName() {
+        return packageName;
+    }
+
+    public void setPackageName(String packageName) {
+        this.packageName = packageName;
+    }
+
+    public String getDbName() {
+        return dbName;
+    }
+
+    public void setDbName(String dbName) {
+        this.dbName = dbName;
+    }
 }

+ 135 - 93
gen/src/main/java/com/gitee/gen/gen/TableDefinition.java

@@ -13,97 +13,139 @@ import java.util.List;
  */
 public class TableDefinition {
 
-	private String tableName; // 表名
-	private String comment; // 注释
-	@JsonIgnore
-	private List<ColumnDefinition> columnDefinitions = Collections.emptyList(); // 字段定义
-
-	public TableDefinition() {
-	}
-
-	public TableDefinition(String tableName) {
-		this.tableName = tableName;
-	}
-
-	/**
-	 * 是否含有时间字段
-	 * @return
-	 */
-	public boolean getHasDateField() {
-		List<ColumnDefinition> columns = getColumnDefinitions();
-		for (ColumnDefinition definition : columns) {
-			if(Date.class.getSimpleName().equals(definition.getJavaType())) {
-				return true;
-			}
-		}
-		return false;
-	}
-
-	public boolean getHasLocalDateField() {
-		List<ColumnDefinition> columns = getColumnDefinitions();
-		for (ColumnDefinition definition : columns) {
-			if(LocalDate.class.getSimpleName().equals(definition.getJavaType())) {
-				return true;
-			}
-		}
-		return false;
-	}
-
-	public boolean getHasLocalDateTimeField() {
-		List<ColumnDefinition> columns = getColumnDefinitions();
-		for (ColumnDefinition definition : columns) {
-			if(LocalDateTime.class.getSimpleName().equals(definition.getJavaType())) {
-				return true;
-			}
-		}
-		return false;
-	}
-
-	/**
-	 * 是否含有BigDecimal字段
-	 * @return
-	 */
-	public boolean getHasBigDecimalField() {
-		List<ColumnDefinition> columns = getColumnDefinitions();
-		for (ColumnDefinition definition : columns) {
-			if("BigDecimal".equals(definition.getJavaType())) {
-				return true;
-			}
-		}
-		return false;
-	}
-
-	public ColumnDefinition getPkColumn() {
-		for (ColumnDefinition column : columnDefinitions) {
-			if (column.getIsPk()) {
-				return column;
-			}
-		}
-		return null;
-	}
-
-	public String getTableName() {
-		return tableName;
-	}
-
-	public void setTableName(String tableName) {
-		this.tableName = tableName;
-	}
-
-	public String getComment() {
-		return comment;
-	}
-
-	public void setComment(String comment) {
-		this.comment = comment;
-	}
-
-	public List<ColumnDefinition> getColumnDefinitions() {
-		return columnDefinitions;
-	}
-
-	public void setColumnDefinitions(List<ColumnDefinition> columnDefinitions) {
-		this.columnDefinitions = columnDefinitions;
-	}
-
+    /**
+     * 表名
+     */
+    private String tableName;
+
+    /**
+     * 表注释
+     */
+    private String comment;
+
+    /** Java相关字段 */
+    private transient List<ColumnDefinition> columnDefinitions = Collections.emptyList();
+
+    /** C#相关字段 */
+    private transient List<CsharpColumnDefinition> csharpColumnDefinitions = Collections.emptyList();
+
+    public TableDefinition() {
+    }
+
+    public TableDefinition(String tableName) {
+        this.tableName = tableName;
+    }
+
+    /**
+     * 是否有时间字段
+     * @return true:有
+     */
+    public boolean getHasDateColumn() {
+        for (ColumnDefinition definition : columnDefinitions) {
+            if (TypeEnum.DATETIME.getType().equalsIgnoreCase(definition.getType())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 是否含有时间字段
+     *
+     * @return
+     */
+    public boolean getHasDateField() {
+        for (ColumnDefinition definition : columnDefinitions) {
+            if (Date.class.getSimpleName().equals(((JavaColumnDefinition) definition).getJavaType())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public boolean getHasLocalDateField() {
+        for (ColumnDefinition definition : columnDefinitions) {
+            if (LocalDate.class.getSimpleName().equals(((JavaColumnDefinition) definition).getJavaType())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public boolean getHasLocalDateTimeField() {
+        for (ColumnDefinition definition : columnDefinitions) {
+            if (LocalDateTime.class.getSimpleName().equals(((JavaColumnDefinition) definition).getJavaType())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 是否含有BigDecimal字段
+     *
+     * @return
+     */
+    public boolean getHasBigDecimalField() {
+        for (ColumnDefinition definition : columnDefinitions) {
+            if ("BigDecimal".equals(((JavaColumnDefinition) definition).getJavaType())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 获取主键信息
+     *
+     * @return 返回主键信息,如果没有则抛出异常
+     */
+    @JsonIgnore
+    public ColumnDefinition getPkColumn() {
+        ColumnDefinition pk = null;
+        for (ColumnDefinition column : columnDefinitions) {
+            if (column.getColumnName().equalsIgnoreCase("id")) {
+                pk = column;
+            }
+            if (column.getIsPk()) {
+                return column;
+            }
+        }
+        if (pk != null) {
+            return pk;
+        }
+        throw new RuntimeException(tableName + "表未设置主键");
+    }
+
+    public String getTableName() {
+        return tableName;
+    }
+
+    public void setTableName(String tableName) {
+        this.tableName = tableName;
+    }
+
+    public String getComment() {
+        return comment;
+    }
+
+    public void setComment(String comment) {
+        this.comment = comment;
+    }
+
+    public List<ColumnDefinition> getColumnDefinitions() {
+        return columnDefinitions;
+    }
+
+    public void setColumnDefinitions(List<ColumnDefinition> columnDefinitions) {
+        this.columnDefinitions = columnDefinitions;
+    }
+
+    public List<CsharpColumnDefinition> getCsharpColumnDefinitions() {
+        return csharpColumnDefinitions;
+    }
+
+    public void setCsharpColumnDefinitions(List<CsharpColumnDefinition> csharpColumnDefinitions) {
+        this.csharpColumnDefinitions = csharpColumnDefinitions;
+    }
 }

+ 15 - 2
gen/src/main/java/com/gitee/gen/gen/TableSelector.java

@@ -1,12 +1,13 @@
 package com.gitee.gen.gen;
 
+import org.springframework.beans.BeanUtils;
 import org.springframework.util.CollectionUtils;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
 public abstract class TableSelector {
@@ -43,13 +44,25 @@ public abstract class TableSelector {
         for (Map<String, Object> rowMap : resultList) {
             TableDefinition tableDefinition = this.buildTableDefinition(rowMap);
             String tableName = tableDefinition.getTableName();
-            tableDefinition.setColumnDefinitions(columnSelector.getColumnDefinitions(tableName));
+            List<ColumnDefinition> columnDefinitions = columnSelector.getColumnDefinitions(tableName);
+            tableDefinition.setColumnDefinitions(buildRealColumnDefinitions(columnDefinitions, JavaColumnDefinition::new));
+            tableDefinition.setCsharpColumnDefinitions(buildRealColumnDefinitions(columnDefinitions, CsharpColumnDefinition::new));
             tablesList.add(tableDefinition);
         }
 
         return tablesList;
     }
 
+    private <T> List<T> buildRealColumnDefinitions(List<ColumnDefinition> columnDefinitions, Supplier<T> supplier) {
+        return columnDefinitions.stream()
+                .map(columnDefinition -> {
+                    T t = supplier.get();
+                    BeanUtils.copyProperties(columnDefinition, t);
+                    return t;
+                })
+                .collect(Collectors.toList());
+    }
+
     public List<TableDefinition> getSimpleTableDefinitions() {
         String showParam = generatorConfig.getDbName();
         // 如果是oracle数据库则传oracle数据库用户大写

+ 43 - 0
gen/src/main/java/com/gitee/gen/gen/TypeEnum.java

@@ -0,0 +1,43 @@
+package com.gitee.gen.gen;
+
+/**
+ * @author tanghc
+ */
+public enum TypeEnum {
+
+    BIT("bit"),
+
+    BOOLEAN("boolean"),
+
+    TINYINT("tinyint"),
+
+    SMALLINT("smallint"),
+
+    INT("int"),
+
+    BIGINT("bigint"),
+
+    FLOAT("float"),
+
+    DOUBLE("double"),
+
+    DECIMAL("decimal"),
+
+    VARCHAR("varchar"),
+
+    DATETIME("datetime"),
+
+    BLOB("blob"),
+
+
+    ;
+    private final String type;
+
+    TypeEnum(String type) {
+        this.type = type;
+    }
+
+    public String getType() {
+        return type;
+    }
+}

+ 75 - 0
gen/src/main/java/com/gitee/gen/gen/TypeFormatter.java

@@ -0,0 +1,75 @@
+package com.gitee.gen.gen;
+
+import org.apache.commons.lang.StringUtils;
+
+import java.util.List;
+
+/**
+ * 将数据库类型格式化成统一的类型
+ *
+ * @author tanghc
+ */
+public interface TypeFormatter {
+
+    default String format(String columnType) {
+        if (isBit(columnType)) {
+            return TypeEnum.BIT.getType();
+        }
+        if (isBoolean(columnType)) {
+            return TypeEnum.BOOLEAN.getType();
+        }
+        if (isTinyint(columnType)) {
+            return TypeEnum.TINYINT.getType();
+        }
+        if (isSmallint(columnType)) {
+            return TypeEnum.SMALLINT.getType();
+        }
+        if (isInt(columnType)) {
+            return TypeEnum.INT.getType();
+        }
+        if (isLong(columnType)) {
+            return TypeEnum.BIGINT.getType();
+        }
+        if (isFloat(columnType)) {
+            return TypeEnum.FLOAT.getType();
+        }
+        if (isDouble(columnType)) {
+            return TypeEnum.DOUBLE.getType();
+        }
+        if (isDecimal(columnType)) {
+            return TypeEnum.DECIMAL.getType();
+        }
+        if (isVarchar(columnType)) {
+            return TypeEnum.VARCHAR.getType();
+        }
+        if (isDatetime(columnType)) {
+            return TypeEnum.DATETIME.getType();
+        }
+        if (isBlob(columnType)) {
+            return TypeEnum.BLOB.getType();
+        }
+        return TypeEnum.VARCHAR.getType();
+    }
+
+    default boolean contains(List<String> columnTypes, String type) {
+        for (String columnType : columnTypes) {
+            if (StringUtils.containsIgnoreCase(type, columnType)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    boolean isBit(String columnType);
+    boolean isBoolean(String columnType);
+    boolean isTinyint(String columnType);
+    boolean isSmallint(String columnType);
+    boolean isInt(String columnType);
+    boolean isLong(String columnType);
+    boolean isFloat(String columnType);
+    boolean isDouble(String columnType);
+    boolean isDecimal(String columnType);
+    boolean isVarchar(String columnType);
+    boolean isDatetime(String columnType);
+    boolean isBlob(String columnType);
+}

+ 22 - 0
gen/src/main/java/com/gitee/gen/gen/converter/ColumnTypeConverter.java

@@ -0,0 +1,22 @@
+package com.gitee.gen.gen.converter;
+
+/**
+ * @author tanghc
+ */
+public interface ColumnTypeConverter {
+
+    /**
+     * 将数据库类型转成基本类型
+     * @param type 数据库类型
+     * @return 基本类型
+     */
+    String convertType(String type);
+
+    /**
+     * 将数据库类型转成装箱类型
+     * @param type 数据库类型
+     * @return 装箱类型
+     */
+    String convertTypeBox(String type);
+
+}

+ 39 - 0
gen/src/main/java/com/gitee/gen/gen/converter/CsharpColumnTypeConverter.java

@@ -0,0 +1,39 @@
+package com.gitee.gen.gen.converter;
+
+import com.gitee.gen.gen.TypeEnum;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author tanghc
+ */
+public class CsharpColumnTypeConverter implements ColumnTypeConverter {
+
+    private static final Map<String, String> TYPE_MAP = new HashMap<>(64);
+    static {
+        TYPE_MAP.put(TypeEnum.BIT.getType(), "bool");
+        TYPE_MAP.put(TypeEnum.BOOLEAN.getType(), "bool");
+        TYPE_MAP.put(TypeEnum.TINYINT.getType(), "byte");
+        TYPE_MAP.put(TypeEnum.SMALLINT.getType(), "int");
+        TYPE_MAP.put(TypeEnum.INT.getType(), "int");
+        TYPE_MAP.put(TypeEnum.BIGINT.getType(), "long");
+        TYPE_MAP.put(TypeEnum.FLOAT.getType(), "float");
+        TYPE_MAP.put(TypeEnum.DOUBLE.getType(), "double");
+        TYPE_MAP.put(TypeEnum.DECIMAL.getType(), "decimal");
+        TYPE_MAP.put(TypeEnum.VARCHAR.getType(), "string");
+        TYPE_MAP.put(TypeEnum.DATETIME.getType(), "DateTime");
+        TYPE_MAP.put(TypeEnum.BLOB.getType(), "byte[]");
+    }
+
+    @Override
+    public String convertType(String type) {
+        return TYPE_MAP.getOrDefault(type, "string");
+    }
+
+    @Override
+    public String convertTypeBox(String type) {
+        return this.convertType(type);
+    }
+
+}

+ 52 - 0
gen/src/main/java/com/gitee/gen/gen/converter/JavaColumnTypeConverter.java

@@ -0,0 +1,52 @@
+package com.gitee.gen.gen.converter;
+
+import com.gitee.gen.gen.TypeEnum;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author tanghc
+ */
+public class JavaColumnTypeConverter implements ColumnTypeConverter {
+
+    private static final Map<String, String> TYPE_MAP = new HashMap<>(64);
+    private static final Map<String, String> TYPE_BOX_MAP = new HashMap<>(64);
+    static {
+        TYPE_MAP.put(TypeEnum.BIT.getType(), "boolean");
+        TYPE_MAP.put(TypeEnum.BOOLEAN.getType(), "boolean");
+        TYPE_MAP.put(TypeEnum.TINYINT.getType(), "byte");
+        TYPE_MAP.put(TypeEnum.SMALLINT.getType(), "short");
+        TYPE_MAP.put(TypeEnum.INT.getType(), "int");
+        TYPE_MAP.put(TypeEnum.BIGINT.getType(), "long");
+        TYPE_MAP.put(TypeEnum.FLOAT.getType(), "float");
+        TYPE_MAP.put(TypeEnum.DOUBLE.getType(), "double");
+        TYPE_MAP.put(TypeEnum.DECIMAL.getType(), "decimal");
+        TYPE_MAP.put(TypeEnum.VARCHAR.getType(), "string");
+        TYPE_MAP.put(TypeEnum.DATETIME.getType(), "Date");
+        TYPE_MAP.put(TypeEnum.BLOB.getType(), "byte[]");
+
+        TYPE_BOX_MAP.put(TypeEnum.BIT.getType(), "Boolean");
+        TYPE_BOX_MAP.put(TypeEnum.BOOLEAN.getType(), "Boolean");
+        TYPE_BOX_MAP.put(TypeEnum.TINYINT.getType(), "Byte");
+        TYPE_BOX_MAP.put(TypeEnum.SMALLINT.getType(), "Short");
+        TYPE_BOX_MAP.put(TypeEnum.INT.getType(), "Integer");
+        TYPE_BOX_MAP.put(TypeEnum.BIGINT.getType(), "Long");
+        TYPE_BOX_MAP.put(TypeEnum.FLOAT.getType(), "Float");
+        TYPE_BOX_MAP.put(TypeEnum.DOUBLE.getType(), "Double");
+        TYPE_BOX_MAP.put(TypeEnum.DECIMAL.getType(), "BigDecimal");
+        TYPE_BOX_MAP.put(TypeEnum.VARCHAR.getType(), "String");
+        TYPE_BOX_MAP.put(TypeEnum.DATETIME.getType(), "Date");
+        TYPE_BOX_MAP.put(TypeEnum.BLOB.getType(), "Byte[]");
+    }
+
+    @Override
+    public String convertType(String type) {
+        return TYPE_MAP.getOrDefault(type, "String");
+    }
+
+    @Override
+    public String convertTypeBox(String type) {
+        return TYPE_BOX_MAP.getOrDefault(type, "String");
+    }
+}

+ 7 - 17
gen/src/main/java/com/gitee/gen/gen/mysql/MySqlColumnSelector.java

@@ -1,9 +1,9 @@
 package com.gitee.gen.gen.mysql;
 
-import com.gitee.gen.gen.GeneratorConfig;
 import com.gitee.gen.gen.ColumnDefinition;
 import com.gitee.gen.gen.ColumnSelector;
-import org.springframework.util.StringUtils;
+import com.gitee.gen.gen.GeneratorConfig;
+import com.gitee.gen.gen.TypeFormatter;
 
 import java.util.Map;
 import java.util.Set;
@@ -13,7 +13,9 @@ import java.util.Set;
  *
  */
 public class MySqlColumnSelector extends ColumnSelector {
-	
+
+	private static final TypeFormatter TYPE_FORMATTER = new MySqlTypeFormatter();
+
 	public MySqlColumnSelector(GeneratorConfig generatorConfig) {
 		super(generatorConfig);
 	}
@@ -48,23 +50,11 @@ public class MySqlColumnSelector extends ColumnSelector {
 		columnDefinition.setIsPk(isPk);
 		
 		String type = (String)rowMap.get("TYPE");
-		columnDefinition.setType(buildType(type));
+		columnDefinition.setType(TYPE_FORMATTER.format(type));
 		
 		columnDefinition.setComment((String)rowMap.get("COMMENT"));
 		
 		return columnDefinition;
 	}
-	
-	// 将varchar(50)转换成VARCHAR
-	private String buildType(String type){
-		if (StringUtils.hasText(type)) {
-			int index = type.indexOf("(");
-			if (index > 0) {
-				return type.substring(0, index).toUpperCase();
-			}
-			return type;
-		}
-		return "VARCHAR";
-	}
-	
+
 }

+ 72 - 0
gen/src/main/java/com/gitee/gen/gen/mysql/MySqlTypeFormatter.java

@@ -0,0 +1,72 @@
+package com.gitee.gen.gen.mysql;
+
+import com.gitee.gen.gen.TypeFormatter;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+/**
+ * @author tanghc
+ */
+public class MySqlTypeFormatter implements TypeFormatter {
+
+    @Override
+    public boolean isBit(String columnType) {
+        return contains(Collections.singletonList("bit"), columnType);
+    }
+
+    @Override
+    public boolean isBoolean(String columnType) {
+        return contains(Collections.singletonList("boolean"), columnType);
+    }
+
+    @Override
+    public boolean isTinyint(String columnType) {
+        return contains(Collections.singletonList("tinyint"), columnType);
+    }
+
+    @Override
+    public boolean isSmallint(String columnType) {
+        return contains(Collections.singletonList("smallint"), columnType);
+    }
+
+    @Override
+    public boolean isInt(String columnType) {
+        return !isLong(columnType) && contains(Arrays.asList("int", "integer"), columnType);
+    }
+
+    @Override
+    public boolean isLong(String columnType) {
+        return !isVarchar(columnType) && contains(Collections.singletonList("bigint"), columnType);
+    }
+
+    @Override
+    public boolean isFloat(String columnType) {
+        return contains(Collections.singletonList("float"), columnType);
+    }
+
+    @Override
+    public boolean isDouble(String columnType) {
+        return contains(Collections.singletonList("double"), columnType);
+    }
+
+    @Override
+    public boolean isDecimal(String columnType) {
+        return contains(Collections.singletonList("decimal"), columnType);
+    }
+
+    @Override
+    public boolean isVarchar(String columnType) {
+        return contains(Arrays.asList("CHAR", "VARCHAR", "TEXT"), columnType);
+    }
+
+    @Override
+    public boolean isDatetime(String columnType) {
+        return contains(Arrays.asList("DATE", "TIME", "DATETIME", "TIMESTAMP"), columnType);
+    }
+
+    @Override
+    public boolean isBlob(String columnType) {
+        return contains(Collections.singletonList("blob"), columnType);
+    }
+}

+ 6 - 21
gen/src/main/java/com/gitee/gen/gen/oracle/OracleColumnSelector.java

@@ -3,7 +3,7 @@ package com.gitee.gen.gen.oracle;
 import com.gitee.gen.gen.ColumnDefinition;
 import com.gitee.gen.gen.ColumnSelector;
 import com.gitee.gen.gen.GeneratorConfig;
-import org.springframework.util.StringUtils;
+import com.gitee.gen.gen.TypeFormatter;
 
 import java.util.Map;
 import java.util.Set;
@@ -12,7 +12,9 @@ import java.util.Set;
  * oracle表信息查询
  */
 public class OracleColumnSelector extends ColumnSelector {
-	
+
+	private static final TypeFormatter TYPE_FORMATTER = new OracleTypeFormatter();
+
 	public OracleColumnSelector(GeneratorConfig generatorConfig) {
 		super(generatorConfig);
 	}
@@ -66,9 +68,6 @@ public class OracleColumnSelector extends ColumnSelector {
 		return sb.toString();
 	}
 	
-	/*
-	 * {FIELD=username, EXTRA=, COMMENT=用户名, COLLATION=utf8_general_ci, PRIVILEGES=select,insert,update,references, KEY=PRI, NULL=NO, DEFAULT=null, TYPE=varchar(20)}
-	 */
 	@Override
 	protected ColumnDefinition buildColumnDefinition(Map<String, Object> rowMap){
 		Set<String> columnSet = rowMap.keySet();
@@ -87,26 +86,12 @@ public class OracleColumnSelector extends ColumnSelector {
 		columnDefinition.setIsPk(isPk);
 		
 		String type = (String)rowMap.get("TYPE");
-		columnDefinition.setType(buildType(type));
+		columnDefinition.setType(TYPE_FORMATTER.format(type));
 		
 		columnDefinition.setComment((String)rowMap.get("COMMENTS"));
 		
 		return columnDefinition;
 	}
 	
-	// 将varchar(50) || 将varchar2 转换成VARCHAR
-	private String buildType(String type){
-		if (StringUtils.hasText(type)) {
-			int index1 = type.indexOf("(");
-			int index2 = type.indexOf("2");
-			if (index1>0) {
-				return type.substring(0, index1).toUpperCase();
-			}else if(index2>0){
-				return type.substring(0, index2).toUpperCase();
-			}
-			return type;
-		}
-		return "VARCHAR";
-	}
-	
+
 }

+ 72 - 0
gen/src/main/java/com/gitee/gen/gen/oracle/OracleTypeFormatter.java

@@ -0,0 +1,72 @@
+package com.gitee.gen.gen.oracle;
+
+import com.gitee.gen.gen.TypeFormatter;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+/**
+ * @author tanghc
+ */
+public class OracleTypeFormatter implements TypeFormatter {
+
+    @Override
+    public boolean isBit(String columnType) {
+        return contains(Collections.singletonList("bit"), columnType);
+    }
+
+    @Override
+    public boolean isBoolean(String columnType) {
+        return contains(Collections.singletonList("boolean"), columnType);
+    }
+
+    @Override
+    public boolean isTinyint(String columnType) {
+        return contains(Collections.singletonList("tinyint"), columnType);
+    }
+
+    @Override
+    public boolean isSmallint(String columnType) {
+        return false;
+    }
+
+    @Override
+    public boolean isInt(String columnType) {
+        return contains(Arrays.asList("int", "integer"), columnType);
+    }
+
+    @Override
+    public boolean isLong(String columnType) {
+        return !isVarchar(columnType) && contains(Collections.singletonList("long"), columnType);
+    }
+
+    @Override
+    public boolean isFloat(String columnType) {
+        return contains(Collections.singletonList("float"), columnType);
+    }
+
+    @Override
+    public boolean isDouble(String columnType) {
+        return contains(Collections.singletonList("double"), columnType);
+    }
+
+    @Override
+    public boolean isDecimal(String columnType) {
+        return contains(Collections.singletonList("decimal"), columnType);
+    }
+
+    @Override
+    public boolean isVarchar(String columnType) {
+        return contains(Arrays.asList("CHAR", "VARCHAR", "VARCHAR2", "NVARCHAR2", "TEXT", "NCHAR"), columnType);
+    }
+
+    @Override
+    public boolean isDatetime(String columnType) {
+        return contains(Arrays.asList("DATE", "TIME", "DATETIME", "TIMESTAMP"), columnType);
+    }
+
+    @Override
+    public boolean isBlob(String columnType) {
+        return contains(Collections.singletonList("blob"), columnType);
+    }
+}

+ 3 - 20
gen/src/main/java/com/gitee/gen/gen/postgresql/PostgreSqlColumnSelector.java

@@ -3,7 +3,6 @@ package com.gitee.gen.gen.postgresql;
 import com.gitee.gen.gen.ColumnDefinition;
 import com.gitee.gen.gen.ColumnSelector;
 import com.gitee.gen.gen.GeneratorConfig;
-import org.springframework.util.StringUtils;
 
 import java.util.Map;
 import java.util.Set;
@@ -15,6 +14,8 @@ import static com.gitee.gen.util.FieldUtil.convertString;
  */
 public class PostgreSqlColumnSelector extends ColumnSelector {
 
+    private static final PostgreSqlTypeFormatter SQL_TYPE_FORMATTER = new PostgreSqlTypeFormatter();
+
     public PostgreSqlColumnSelector(GeneratorConfig dataBaseConfig) {
         super(dataBaseConfig);
     }
@@ -70,29 +71,11 @@ public class PostgreSqlColumnSelector extends ColumnSelector {
         columnDefinition.setIsPk(isPk);
 
         String type = convertString(rowMap.get("TYPE"));
-        columnDefinition.setType(buildType(type));
+        columnDefinition.setType(SQL_TYPE_FORMATTER.format(type));
 
         columnDefinition.setComment(convertString(rowMap.get("CMT")));
 
         return columnDefinition;
     }
 
-    private String buildType(String type){
-        if (StringUtils.hasText(type)) {
-            if ("character varying".equals(type)) {
-                return "VARCHAR";
-            }
-            if (type.contains("timestamp")) {
-                return "TIMESTAMP";
-            }
-            if (type.contains("double")) {
-                return "double";
-            }
-            if (type.contains("real")) {
-                return "float";
-            }
-            return type;
-        }
-        return "VARCHAR";
-    }
 }

+ 72 - 0
gen/src/main/java/com/gitee/gen/gen/postgresql/PostgreSqlTypeFormatter.java

@@ -0,0 +1,72 @@
+package com.gitee.gen.gen.postgresql;
+
+import com.gitee.gen.gen.TypeFormatter;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+/**
+ * @author tanghc
+ */
+public class PostgreSqlTypeFormatter implements TypeFormatter {
+
+    @Override
+    public boolean isBit(String columnType) {
+        return contains(Collections.singletonList("bit"), columnType);
+    }
+
+    @Override
+    public boolean isBoolean(String columnType) {
+        return contains(Collections.singletonList("boolean"), columnType);
+    }
+
+    @Override
+    public boolean isTinyint(String columnType) {
+        return contains(Arrays.asList("int2", "serial2", "smallint"), columnType);
+    }
+
+    @Override
+    public boolean isSmallint(String columnType) {
+        return false;
+    }
+
+    @Override
+    public boolean isInt(String columnType) {
+        return contains(Arrays.asList("int4", "serial4", "integer"), columnType);
+    }
+
+    @Override
+    public boolean isLong(String columnType) {
+        return !isVarchar(columnType) && contains(Arrays.asList("int8", "serial8", "bigint"), columnType);
+    }
+
+    @Override
+    public boolean isFloat(String columnType) {
+        return contains(Arrays.asList("float", "real"), columnType);
+    }
+
+    @Override
+    public boolean isDouble(String columnType) {
+        return contains(Collections.singletonList("double"), columnType);
+    }
+
+    @Override
+    public boolean isDecimal(String columnType) {
+        return contains(Arrays.asList("decimal","numeric"), columnType);
+    }
+
+    @Override
+    public boolean isVarchar(String columnType) {
+        return contains(Arrays.asList("CHAR", "VARCHAR", "TEXT", "character", "json"), columnType);
+    }
+
+    @Override
+    public boolean isDatetime(String columnType) {
+        return contains(Arrays.asList("DATE", "TIME", "DATETIME", "TIMESTAMP"), columnType);
+    }
+
+    @Override
+    public boolean isBlob(String columnType) {
+        return contains(Collections.singletonList("blob"), columnType);
+    }
+}

+ 1 - 0
gen/src/main/java/com/gitee/gen/service/GeneratorService.java

@@ -100,6 +100,7 @@ public class GeneratorService {
         context.put("table", sqlContext.getTableDefinition());
         context.put("pk", sqlContext.getTableDefinition().getPkColumn());
         context.put("columns", sqlContext.getTableDefinition().getColumnDefinitions());
+        context.put("csharpColumns", sqlContext.getTableDefinition().getCsharpColumnDefinitions());
 
         return VelocityUtil.generate(context, template);
     }

+ 0 - 20
gen/src/main/java/com/gitee/gen/util/DateUtil.java

@@ -1,20 +0,0 @@
-package com.gitee.gen.util;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-public class DateUtil {
-	private static DateFormat YMDHMS_FORMAT = new SimpleDateFormat(
-			"yyyy-MM-dd HH:mm:ss.sss");
-	private static DateFormat YMD_FORMAT = new SimpleDateFormat(
-			"yyyy-MM-dd");
-
-	public static String ymdhmsFormat(Date date) {
-		return YMDHMS_FORMAT.format(date);
-	}
-	public static String ymdFormat(Date date) {
-		return YMD_FORMAT.format(date);
-	}
-
-}

+ 1 - 0
gen/src/main/java/com/gitee/gen/util/SqlTypeUtil.java

@@ -47,6 +47,7 @@ public class SqlTypeUtil {
 		javaBoxTypeMap.put("bigint", "Long");
 		javaBoxTypeMap.put("binary", "Byte[]");
 		javaBoxTypeMap.put("bit", "Boolean");
+		javaBoxTypeMap.put("bool", "Boolean");
 		javaBoxTypeMap.put("boolean", "Boolean");
 		javaBoxTypeMap.put("blob", "Byte[]");
 		javaBoxTypeMap.put("char", "String");