Giter Club home page Giter Club logo

fastcode's Introduction

自动代码生成工具

  • 基于node.js 的代码生成工具,理论上支持所有语言。 采用模板机制,模板需要自己改写,建议把自己项目中的代码复制一份为模板,然后进行修改。
  • 数据库暂时只支持mysql系列。
  • 纯java版的代码生成器

模板引擎 art-template

  • 如果你知道基于JavaScript的模板引擎,那么入手会相当容易。art-template 是一个渲染速度极快的JavaScript模板引擎。 具体语法请看官方的教程:中文语法教程
  • 几个语法的例子

运行

  • 在第一次下载本项目后,运行命令
npm install
  • 启动生成
npm start

文件说明

文件名 说明
builder.js 模板生成入口
config.js 配置文件

字段取名规则

数据库中大写字段均会转为小写赋值到fieldName中 columnName 还是原样输出

模板中的字段取名规则参考驼峰命名例如:

  • user_id取值为userId
  • USERID 取值为userid,
  • user_id_name_abc 取值为userIdNameAbc

模板内变量

  • 全局字段

    字段名 说明
    packageName 包名,例如:com.88cto.xxx
    modelRemark 模块注释
    author 作者
    now 当前时间,例如:2018-12-11 18:08:48
    url 访问地址
    modelName 模块名
    idColumn id列,数据库中的id列,取第一个id字段,多个id字段请自行处理
    idField id字段名,名字根据idColumn生成,生成规则参考字段取名规则
    columns 列字段columns字段
  • columns字段

    字段名 说明
    columnName 列名
    fieldName 字段名,字段取名规则
    typeName 类型名,Java类型名称,通过配置文件的映射配置
    remark 数据库中的注释
    type 数据库中的类型

模板示例

  • 变量定义
    <% var date=new Date(); %>
  • 取值
    <% var date=new Date(); %>
   <div>今天的日期是:${date}</div>
  • if语句
    <%
    var aa=123; 
    if (aa==123){
    
    %>
    
    <div>aa等于123</div>
    
    <%}%>
  • for循环
    <%for(var i=0;i<100;i++){%>
    <div>${i}</div>
    <%}%>
  • 内置过滤器

    过滤器使用{{}}两个括号,加|,语法参考ejs,或者art-template官方文档

    • 首字母大写 up_first
          <% var aa="china" %>
          {{aa | up_first}}
      输出 China
    • 首字母小写 low_first
          <% var aa="China" %>
          {{aa | up_first}}
      输出 china

fastcode's People

Contributors

newpanjing avatar

Watchers

James Cloos avatar  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.