<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Tao

    Tao obeys its own inherent Nature

    Introduce a tool to generate code by writing JavaScript

    Java Based Code Generator - jbcgen

    home page:

    http://sourceforge.net/projects/jbcgen/

    Short Description:

    This code generator generates files from database and templates written in JavaScript. it supports db plugin, and it's easy to extend and use. It supports mysql and db which support ado connection(under windows only) for now. 

    When To Use

    It should be used especially when the code logic is similar, but the table is different. It will save much of your time by generating code automatically instead of copy&paste. For example, you want to write 5 files for each table, you only need to write lines of javascript code without coding the files lots of time.

    Why To Use

    The reason is very simple, the program is very simple and it will save much of your time.

    A very simple example:

    public class Base<%=getDomainByTable(sys_table_name)%>{
    <$
    for (var i=0; i<sys_fields.length; i++)
    {
    var type = getJavaBeanType(sys_fields[i].type);$>
    private <%=type%> <%=sys_fields[i].name%>;
    <$
    }

    for (var i=0; i<sys_fields.length; i++)
    {
    var type = getJavaBeanType(sys_fields[i].type);
    $>
    public <%=type%> get<%=formatFieldName(sys_fields[i].name)%>(){
    return <%=sys_fields[i].name%>;
    }
    public void set<%=formatFieldName(sys_fields[i].name)%> (<%=type%> <%=sys_fields[i].name%>){
    this.<%=sys_fields[i].name%> = <%=sys_fields[i].name%>;
    }
    <$
    }
    $>
    }
     
    If the current table has role_id int, role_name varchar, description varchar, then the result will be:

    public class BaseRole{
    private int role_id;
    private String role_name;
    private String description;

    public int getRoleId(){
    return role_id;
    }
    public void setRoleId (int role_id){
    this.role_id = role_id;
    }
    public String getRoleName(){
    return role_name;
    }
    public void setRoleName (String role_name){
    this.role_name = role_name;
    }
    public String getDescription(){
    return description;
    }
    public void setDescription (String description){
    this.description = description;
    }
    }

    Script Tag:

    1. <$
            //Javascript code like: println(sys_fields[0].name);
      $>
    2. <$=sys_fields[0].name$>

    Predefined variables:

    1. sys_table_name: current selected table name
    2. sys_fields: Array of Field object. use sys_fields.length to get the field count of current table.
    3. sys_keys: Array of Primary key column, use sys_keys.length to get the field count of current table.
    4. sys_user_name: User name used to connect to current database.
    5. sys_db_name: Database name used to connect to.
    6. sys_output: Internal use only which store the temporary generated code. User can use it too by println(sys_output).
    7. Field Object, if there's a field: user_name varchar(100) not null default 'user', here's the available fields and values:
          name: field name, String. For Example: sys_fields[i].name, example value is user_name
          type: field type, String, For Example: sys_fields[i].type, example value is varchar
          size: field length, integer, For Example: sys_fields[i].size, example value is 100
          scale: field scale, integer, For Example: sys_fields[i].scale, not available in this case
          default_value: Default value for the field, String. For Example: sys_fields[i].default_value, example value is user
          is_null: if the field can be null or not, boolean. For Example: sys_fields[i].is_null, example value is false
          is_primary_key: if the field is primary key, boolean. For Example: sys_fields[i].is_primary_key, example value is false.
    8. sys_tables: all table's name in current database.

    Predefined Functions:

    1. print(str). Print the code without new line.
    2. println(str). Print the code with new line.
    3. getFieldList(). Return field list separated by ','
    4. And a few other javascript functions, like capitalize, lowercase, uppercase, trim, etc. which you can add your own by Tools/Edit public functions

    Steps to use this program:

    1. Create a project
    2. Add folder(s) and templates, template is written in JavaScript, and the only difference is it need the following format: <$ you code$> or <%=expression%>
    3. Generate files for multiple tables and templates(folders)

     

    DB Connection Setting

    Steps to config the database:

    1. Select Database Type. Click next.
    2. Input required information like host, port, username, password and database name depends on your database type.

    Generate Files

    Generate current file, Template/Generate current file

    Generate project files, Project/Generate Project Files

    Batch Generate, Project/Batch Generate, and then select tables and templates(folders) to generate files

    Tips

    1. use JavaScript map instead of if ... else ...
      <$
      var type_defaultvalue={
      'int':'0',
      'tinyint':'false',
      'varchar':'""',
      'datetime':'new Date()',
      };

      for (var i=0; i<sys_fields.length; i++)
      {
      var type = sys_fields[i].type;

      if(undef(type_defaultvalue[type])){
      println("Undefined default value for field type: '"+ type+"'");
      }

      //the following line has the same result //println(sys_table_name+".set"+formatFieldName(sys_fields[i].name)+"("+type_defaultvalue[type] + ");"); $> <%=sys_table_name%>.set<%=formatFieldName(sys_fields[i].name)%>(<%=type_defaultvalue[type] %>); <$ } $>
    2. write JavaScript function for project in project properties, and call them to put different tables in different place, e.g.
      function getModule(tablename){
           if(tablename.startsWith('user')){
               return "user/";
          }
          //code to return other module name
          //...
          return "";
      }
      and set the destination path for folder or template using this function: <%=getModule(sys_table_name)%><%=getDomainByTable(sys_table_name)%>Action.java, then if the current table is user, the destination path will be: user/UserAction.java, and if the table is log, then the destination page will be: LogAction.java

    Improve this program:

    Please write to me if:

    1. You need other type db connection or you wrote another db plugin
    2. You don't know how to use it
    3. If you found any bug(s)
    4. Any suggestion and anything else...

     

    Hope it's useful for you. And hope it will decrease your time of copy & paste.

    posted on 2008-03-04 22:48 wade 閱讀(897) 評(píng)論(0)  編輯  收藏 所屬分類: C++JavaJavascript

    導(dǎo)航

    <2008年3月>
    2425262728291
    2345678
    9101112131415
    16171819202122
    23242526272829
    303112345

    統(tǒng)計(jì)

    常用鏈接

    留言簿(7)

    隨筆分類

    隨筆檔案

    相冊(cè)

    Photo

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 亚洲日本香蕉视频| 国产精品亚洲片在线花蝴蝶| 国内自产少妇自拍区免费| 蜜桃传媒一区二区亚洲AV| 亚洲人成人无码网www电影首页| 亚洲黄色片免费看| 美女被爆羞羞网站免费| 久久伊人久久亚洲综合| 大学生高清一级毛片免费| 三级黄色免费观看| 亚洲伊人久久大香线焦| 亚洲一区视频在线播放| 日韩欧毛片免费视频| xxxxx做受大片视频免费| 亚洲免费在线观看视频| 国产成人精品亚洲精品| 亚洲高清中文字幕免费| 一区二区三区在线免费观看视频 | 亚洲成av人片在线看片| 亚洲AV无码一区二三区| 91九色精品国产免费| 久久国产美女免费观看精品| 国产成人精品日本亚洲专区6| 国产亚洲成AV人片在线观黄桃| 天天天欲色欲色WWW免费| 免费A级毛片无码A∨| 免费在线观看自拍性爱视频| 亚洲日产2021三区在线 | 亚洲国产成人久久精品影视 | 亚洲成年人电影在线观看| 亚洲VA综合VA国产产VA中| 成年黄网站色大免费全看| 三级毛片在线免费观看| 一级中文字幕乱码免费| 亚洲人成电影网站免费| 亚洲成人高清在线观看| 久久亚洲免费视频| 亚洲精品一品区二品区三品区| 四虎永久在线精品免费影视 | www国产亚洲精品久久久| 成人毛片免费观看视频在线|