Start MyBatis generator with Java

Source: Internet
Author: User

1. Java Project directory structure:

|src/main/java

|com.leslie.mybatis.generator

| Mybatisgeneratorutil.java

|src/main/resources

Generatorconfig.xml

|lib

|mybatis-3.3.0.jar

|mybatis-generator-core-1.3.2.jar

|mysql-connector-java-5.1.14-bin.jar

2, Mybatisgeneratorutil.java

 PackageCom.leslie.mybatis.generator;ImportJava.io.File;Importjava.io.IOException;Importjava.sql.SQLException;Importjava.util.ArrayList;Importjava.util.List;ImportOrg.mybatis.generator.api.MyBatisGenerator;Importorg.mybatis.generator.config.Configuration;ImportOrg.mybatis.generator.config.xml.ConfigurationParser;Importorg.mybatis.generator.exception.InvalidConfigurationException;Importorg.mybatis.generator.exception.XMLParserException;ImportOrg.mybatis.generator.internal.DefaultShellCallback; Public classMybatisgeneratorutil { Public Static voidMain (string[] args) {Try{System.out.println ("Start generator ..."); List<String> warnings =NewArraylist<string>(); BooleanOverwrite =true; File ConfigFile=NewFile (Mybatisgeneratorutil.class. GetResource ("/generatorconfig.xml"). GetFile ()); Configurationparser CP=Newconfigurationparser (warnings); Configuration Config=cp.parseconfiguration (configfile); Defaultshellcallback Callback=Newdefaultshellcallback (overwrite); Mybatisgenerator Mybatisgenerator=Newmybatisgenerator (config, callback, warnings); Mybatisgenerator.generate (NULL); System.out.println ("End generator!"); } Catch(IOException e) {e.printstacktrace (); } Catch(xmlparserexception e) {e.printstacktrace (); } Catch(invalidconfigurationexception e) {e.printstacktrace (); } Catch(SQLException e) {e.printstacktrace (); } Catch(interruptedexception e) {e.printstacktrace (); }    }}

3, Generatorconfig.xml

<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis Generator Configuration 1.0//en" "/http Mybatis.org/dtd/mybatis-generator-config_1_0.dtd "><generatorconfiguration>        <Classpathentry Location= "D:\svn\MyBatisGenerator\lib\mysql-connector-java-5.1.14-bin.jar" />        <ContextID= "Db2tables"Targetruntime= "MyBatis3">        <Commentgenerator>            < Propertyname= "Suppressdate"value= "true"/>            < Propertyname= "Suppressallcomments"value= "true"/>        </Commentgenerator>        <jdbcconnectionDriverclass= "Com.mysql.jdbc.Driver"Connectionurl= "Jdbc:mysql://192.168.0.39:3306/leslie?useunicode=true&amp;characterencoding=utf-8"userId= "Leslie"Password= "123456" >        </jdbcconnection>                <Javatyperesolver>            < Propertyname= "Forcebigdecimals"value= "false"/>        </Javatyperesolver>        <JavamodelgeneratorTargetpackage= "Com.wsj.ygbh.model"Targetproject= "src">            < Propertyname= "Enablesubpackages"value= "true"/>            < Propertyname= "Trimstrings"value= "true"/>        </Javamodelgenerator>        <SqlmapgeneratorTargetpackage= "Com.wsj.ygbh.mapping"Targetproject= "src">            < Propertyname= "Enablesubpackages"value= "true"/>        </Sqlmapgenerator>        <Javaclientgeneratortype= "Xmlmapper"Targetpackage= "Com.wsj.ygbh.dao"Targetproject= "src">            < Propertyname= "Enablesubpackages"value= "true"/>        </Javaclientgenerator>                        <TableTableName= "Leslie_ad"Domainobjectname= "Ad"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"></Table>        <TableTableName= "Leslie_ad_position"Domainobjectname= "Adposition"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"></Table>                    </Context></generatorconfiguration>

Start MyBatis generator with Java

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.