1 Star 0 Fork 147

bbf / CodeGenerator

forked from ptma / CodeGenerator 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

CodeGenerator

这是一个使用 Freemarker 和 Velocity 模板来生代码的工具。

本生成器只是将数据库中的表结构数据提取出来,然后将这份结构模型提交给模板引擎, 根据你自定义的模板生成你需要的代码。

配置文件

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<configuration>
  <classpath>
    <!-- 引入JDBC驱动,手动添加 -->
    <entry>lib/mysql-connector-java-5.1.36-bin.jar</entry>
  </classpath>
  <!-- 代码生成目标基准目录 -->
  <targetProject>D:\temp</targetProject>
  <!-- 基本包 -->
  <basePackage>org.joy</basePackage>
  <!-- 模块名 -->
  <moduleName>test</moduleName>
  <templates>
    <!-- 模板 ,手动添加 -->
    <template name="实体类" engine="freemarker">
      <!-- 模板文件 -->
      <templateFile>./entity.ftl</templateFile>
      <!-- 文件路径 -->
      <targetPath>${targetProject}\src\${basePackage}\${moduleName}\entity\</targetPath>
      <!-- 文件名 -->
      <targetFileName>${table.className}.java</targetFileName>
      <!-- 文件编码 -->
      <fileEncoding>UTF-8</fileEncoding>
    </template>
  </templates>
</configuration>

模板中可用的变量和方法

类型 属性名 说明
String targetProject 目标工程路径(代码保存的基准路径)
String basePackage 基准包
String moduleName 模块名
String author 开发者
Map<String, Boolean> template 模板是否可用(是否勾选生成)

Table对象

可用的属性

类型 属性名 说明
String tableName 表名
String tableType 表类型
String tableAlias 表别名
String remarks 表注释
String remarksUnicode 表注释转Unicode后的字符串
String className 实体类名
String javaProperty 实体类作为属性时的名字 == ${table.className?uncap_first}
List primaryKeys 主键集
List baseColumns 基本字段集
List columns 所有字段 == primaryKeys + baseColumns
List importedKeys 所有importedKeys
List exportedKeys 所有exportedKeys
boolean hasDateColumn 是否有日期类型字段
boolean hasBigDecimalColumn 是否有BigDecimal 字段
boolean hasNotNullColumn 是否有非空的基本类型字段
boolean hasNotBlankColumn 是否有非空的String 字段
boolean hasSearchableColumn 是否有可搜索的字段

Column对象

属性

类型 属性名 说明
String columnName 字段名
boolean primaryKey 是否为主键
boolean foreignKey 是否为外键
int size 字段长度
int decimalDigits 小数位长度
boolean nullable 是否可空
boolean autoincrement 是否自增
boolean unique 是否唯一值
boolean indexed 是否有索引
String defaultValue 默认值
String remarks 注释
String remarksUnicode 数字转Unicode后的字符串
int jdbcType 对应的java.sql.Types
String jdbcTypeName 对应jdbcType的名称
String javaProperty 属性名
String javaType java类型,比如String、Long、Integer
String javaPrimitiveType java基本类型,如果不是基本类型时等同于javaType
String fullJavaType 完整的Java类型,比如java.lang.String
String getterMethodName Get方法名
String setterMethodName Set方法名
boolean display 是否显示
boolean searchable 是否可搜索
boolean sortable 是否可排序
String dict 数据字典名

方法

类型 属性名 说明
boolean isString() 是否是字符串
boolean isFloatNumber() 是否是浮点型,含Float、Double、BigDecimal
boolean isIntegerNumber() 是否是整型,含Byte、Short、Integer、Long
boolean isBigDecimal() 是否是BigDecimal类型
boolean isBoolean() 是否是布尔类型
boolean isDate() 是否有日期类型,含Date、Timestamp、Time
boolean isBLOB() 是否有BLOB、CLOB、LONGVARCHAR、LONGVARBINARY或VARBINARY
boolean isPrimitiveType() 是否是基本类型
boolean hasDict() 是否使用了数据字典

Key

类型 属性名 说明
String pkTableName PKTABLE_NAME
String pkColumnName PKCOLUMN_NAME
String fkTableName FKTABLE_NAME
String fkColumnName FKCOLUMN_NAME
Integer seq KEY_SEQ

##作者 ptma@163.com

Copyright 2014 ptma@163.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

可视化代码生成器, 可同时使用FreeMarker 和 Velocity 模板 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/bbfbbf/CodeGenerator.git
git@gitee.com:bbfbbf/CodeGenerator.git
bbfbbf
CodeGenerator
CodeGenerator
master

搜索帮助