Code Monkey home page Code Monkey logo

rapid-generator's Introduction

rapid-generator

半自动化Java代码生成器[利用freemarker模板生成]

本项目Github地址: https://github.com/yuchenggroup/rapid-generator

项目最初来自于 https://code.google.com/p/rapid-generator/

增加一些定制和扩展, 修改为基于MAVEN的格式。 整体架构保持不变。

增加的特性为:

  1. 支持表名前缀去除,参考配置文件中的 tableRemovePrefixes
  2. 支持列名前缀去除,参考配置文件中的 rowRemovePrefixes
  3. 支持需要忽略的表,参考配置文件中的 skipTablePrefixes
  4. 支持子包,参考配置文件中的 subpackage,其实原版就支持, 目录为属性KEY加上 _dir 即可,例如 "${xxxKEY_dir}"
  5. 其他一些模板使用上的修正,参考 template 目录

需要一个依赖: FreeMarker, 手册地址: http://yuchenggroup.github.io/rapid-generator/FreeMarker_2.3.23_Manual_zh_CN/index.html

开始日期: 2016年1月21日

使用说明

1. 构建项目/编译

执行 maven_clean_package.cmd 文件或者以下命令进行编译:

mvn clean package -DskipTests

编译后的文件在 target/bin 目录下。 目录结构为:

|--lib\				: 依赖库
|--template\		: 模板文件
|--generator.xml	: 配置文件
|--rapid-gen.bat	: Win32脚本文件

2. 代码生成

2.1 启动生成器

bin目录拷贝到需要的地方, 这就是生成文件需要的东西。

拷贝好之后, 修改generator.xml,需要修改的 entry 包括:

basepackage
subpackage
jdbc.url
jdbc.username
jdbc.password

双击执行rapid-gen.bat文件,或者执行命令:

Windows下:

set classpath=%classpath%;.;.\lib\*

java -Xms128m -Xmx384m cn.org.rapid_framework.generator.ext.CommandLine -DtemplateRootDir=template

Linux 系统使用 export 设置环境变量。

Linux 系统(未验证!!):

以及MacOSX系统:

java -classpath '.:./lib/*'  -Xms128m -Xmx384m cn.org.rapid_framework.generator.ext.CommandLine -DtemplateRootDir=template

2.2 使用生成器

启动之后如果不报错,则提示信息为:

templateRootDir:E:\00_GIT_ALL\rapid-generator\target\bin\template
Usage:
        gen table_name [include_path]: 根据 table_name 生成
        del table_name [include_path]: 根据 table_name 删除
        gen * [include_path]: 生成所有
        del * [include_path]: 删除对应数据库中所有表的文件
        quit : 退出
        [include_path] 可为空,指templateRootDir的子目录,例如: 1. dao  2. dao/**,service/**
please input command:_

根据提示, 输入 gen * 回车,则对所有表进行生成。

输入 gen 表名 则是生成单个表。

生成之后的目录默认为 generator-output

生成完毕之后,因为这是一个半自动生成器,所以需要手工拷贝代码。

这也是合理的,因为代码开发是程序员的事。 这不是自动编译或者发布,所以。。。

2.3 其他

默认的模板是为项目 cncounter-web 生成的, 项目地址为:

https://github.com/cncounter/cncounter

Controller层需要依赖的文件存放于 template/cnc_main/other_java_file目录下,请根据需要进行使用。

  • 高级用法请自己摸索。
  • template 下可以自己进行修改,可以参考源码,以及 Freemarker的官方文档(见上方)。
  • 配置文件信息,请参考generator.xml里面的注释。

freemarker中key有特殊字符,如(.-等)

root key 使用:
.vars["aaaa.bbb"]
.vars["aaaa-bbb"]

非root key 使用:
ccc["ddd.eee"]
ccc["ddd-eee"]

联系方式: [email protected]

如果你对整套的代码生成方案感兴趣,也可以参考:

rapid-generator's People

Contributors

renfufei avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.