Java Code generation Tool Rapid-generate application two __java

Source: Internet
Author: User
Tags db2 generator postgresql sybase

In the last section we briefly introduced what Rapid-generate can do, and demonstrated the test code with the tool, which we will apply to our project in conjunction with MySQL.

Step One: new Java Project Project, Copy the Generate.xml files and template folders in the Rapid-generate, and introduce the 3 jar packages on which you rely, Freemarker.jar,mysql-connector-java-5.0.5-bin.jar,rapid-ge Nerator.jar.

Step Two: Create a new Test.java class with the following code:

Package AA;

Import Cn.org.rapid_framework.generator.GeneratorFacade;

public class Test {public
    static void Main (String[]args) throws exception{
        generatorfacade g = new Generatorfacad E ();
        G.deleteoutrootdir ();
        Deletes the generator's output directory//
        //g.generatebytable ("table_name", "template");
        The file is generated from the database table, and the template is the root directory
        g.generatebyalltable ("template") of the template;
        Automatically searches all tables in the database and generates files, template the root directory of the template
        //g.generatebyclass (blog.class, "Template_clazz");  g.deletebytable ("table_name", "template");
        Delete the generated file
    }
}

Step Three: modify Generator.xml According to your requirements, here we use the MySQL database.

<?xml version= "1.0" encoding= "GBK"?> <! DOCTYPE Properties SYSTEM "Http://java.sun.com/dtd/properties.dtd" > <properties> <comment> code generation Configuration file: 1. Property_dir attributes are generated for all properties, such as Pkg=com.company => Pkg_dir=com/company 2. You can reference environment variables: ${env. Java_home} or System.properties: ${user.home},property can also be cross-referenced to each other </comment> <entry key= "Basepackage" >c Om.company.project</entry> <!--jsp namespace:web/${namespace}/${classname}/list.jsp--> <entry k Ey= "namespace" >pages</entry> <entry key= "Outroot" >f:\2013-2014\eclipse-j2ee\workspace\ Rapid-generator-pro\out-put</entry> <!--need to remove the table name prefix, using commas to separate multiple prefixes, example value: T_,v_--> <entry key= "Tablere Moveprefixes "></entry> <entry key=" Jdbc.username ">root</entry> <entry key=" Jdbc.password " >root</entry> <!--Oracle needs to specify Jdbc.schema, other databases ignore this configuration--> <entry key= "Jdbc.schema" ></entry> <entry key= "Jdbc.catalog" ></entry> <!--database type mappings--> <entry key= "Java_typemappi Ng.java.sql.Timestamp ">java.util.Date</entry> <entry key=" Java_typemapping.java.sql.Date "> java.util.date</entry> <entry key= "Java_typemapping.java.sql.Time" >java.util.Date</entry> < Entry key= "Java_typemapping.java.lang.Byte" >Integer</entry> <entry key= "Java_" Typemapping.java.lang.Short ">Integer</entry> <entry key=" Java_typemapping.java.math.BigDecimal "> long</entry> <!--H2--> <!--<entry key= "Jdbc.url" >jdbc:h2:tcp://localhost/test</entry&gt
    ; <entry key= "Jdbc.driver" >org.h2.Driver</entry>--> <!--Mysql--> <entry key= "Jdbc.url" ;jdbc:mysql://localhost:3306/tgdb?useunicode=true&amp;characterencoding=utf-8</entry> <entry key= "  Jdbc.driver ">com.mysql.jdbc.Driver</entry> <!--Oracle   Jdbc:oracle:oci: @tnsname_devdb <entry key= "Jdbc.url" >jdbc:oracle:thin:@192.168.0.177:1521:[sid]</entry&
    Gt <entry key= "Jdbc.driver" >oracle.jdbc.driver.OracleDriver</entry>--> <!--SQLServer2000 &L T;entry key= "Jdbc.url" >jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=[database]</entry> < Entry key= "Jdbc.driver" >com.microsoft.jdbc.sqlserver.SQLServerDriver</entry>--> <!--SQLServer200 5 <entry key= "Jdbc.url" >jdbc:sqlserver://192.168.0.98:1433;DatabaseName=[database]</entry> <entry  
    key= "Jdbc.driver" >com.microsoft.sqlserver.jdbc.SQLServerDriver</entry>--> <!--jtds for SQL Server <entry key= "Jdbc.url" >jdbc:jtds:sqlserver://192.168.0.102:1433/[database];tds=8.0;lastupdatecount=true </entry> <entry key= "Jdbc.driver" >net.sourceforge.jtds.jdbc.Driver</entry>--> <!--P Ostgresql <entry key= "jdbc.uRL ">jdbc:postgresql://localhost/[database]</entry> <entry key=" Jdbc.driver ">org.postgresql.driver </entry>--> <!--Sybase <entry key= "Jdbc.url" &GT;JDBC:SYBASE:TDS:LOCALHOST:5007/[DATABASE]&L 
    t;/entry> <entry key= "Jdbc.driver" >com.sybase.jdbc.SybDriver</entry>--> <!--DB2 <entry key= "Jdbc.url" >jdbc:db2://localhost:5000/[database]</entry> <entry key= "Jdbc.driver" > Com.ibm.db2.jdbc.app.db2driver</entry>--> <!--HsqlDB <entry key= "Jdbc.url" >jdbc:hsqldb:m em:generatordb</entry> <entry key= "Jdbc.driver" >org.hsqldb.jdbcDriver</entry>--> <!- -Derby <entry key= "Jdbc.url" >jdbc:derby://localhost/databaseName</entry> <entry key= "Jdbc.driver"
 >org.apache.derby.jdbc.ClientDriver</entry>--> </properties>

Step Four: We run the main function in test, see the console has output log, and refresh the item, the Out-put directory appears.

So far, we have successfully integrated the Rapid-generate builder into our own projects, connecting MySQL database tgdb, generating table user's DAO layer, controller layer, view layer, model layer.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.