Mybatis Reverse Engineering

Source: Internet
Author: User

MyBatis Reverse Engineering:

It is recommended to generate reverse files in Java and XML configuration

Java class:

 Packagegeneration;ImportJava.io.File;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.internal.DefaultShellCallback; Public classGeneration { Public voidGeneration ()throwsException {List<String> warnings =NewArraylist<string>(); BooleanOverwrite =true; File ConfigFile=NewFile ("Generatorconfig.xml"); Configurationparser CP=Newconfigurationparser (warnings); Configuration Config=cp.parseconfiguration (configfile); Defaultshellcallback Callback=Newdefaultshellcallback (overwrite); Mybatisgenerator Mybatisgenerator=Newmybatisgenerator (config, callback, warnings); Mybatisgenerator.generate (NULL); }     Public Static voidMain (string[] args) {Generation Generation=NewGeneration (); Try{generation.generation (); } Catch(Exception e) {e.printstacktrace (); }    }}

XML configuration:

<?XML version= "1.0" encoding= "UTF-8"?>  <!DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis Generator Configuration 1.0//en" "Http://myba Tis.org/dtd/mybatis-generator-config_1_0.dtd "><generatorconfiguration>    <!--Database-driven -    <Classpathentry Location= "E:\JavaPack\JAR\MySQL\mysql-connector-java-5.1.28-bin.jar" />    <ContextID= "Db2tables"Targetruntime= "MyBatis3">        <Commentgenerator>            < Propertyname= "Suppressdate"value= "true" />            < Propertyname= "Suppressallcomments"value= "true" />        </Commentgenerator>        <!--Database link Address account password -        <jdbcconnectionDriverclass= "Com.mysql.jdbc.Driver"Connectionurl= "Jdbc:mysql://172.22.144.214/hainan"userId= "root"Password= "Abcd1234">        </jdbcconnection>        <!--by default, the JDBC decimal and NUMERIC types are parsed to Integer, and the JDBC decimal and NUMERIC types are resolved to Java.math.BigDecimal if True 
      -        <Javatyperesolver>            < Propertyname= "Forcebigdecimals"value= "false" />        </Javatyperesolver>        <!--generate model class storage location -        <JavamodelgeneratorTargetpackage= "Cn.edu.hainan.model"Targetproject= "src">            < Propertyname= "Enablesubpackages"value= "true" />            < Propertyname= "Trimstrings"value= "true" />                    </Javamodelgenerator>        <!--Generate Map File storage location -        <SqlmapgeneratorTargetpackage= "Cn.edu.hainan.mapper"Targetproject= "src">            < Propertyname= "Enablesubpackages"value= "true" />        </Sqlmapgenerator>        <!--generate a DAO class storage location -        <Javaclientgeneratortype= "Xmlmapper"Targetpackage= "Cn.edu.hainan.mapper"Targetproject= "src">            < Propertyname= "Enablesubpackages"value= "true" />        </Javaclientgenerator>        <!--generate the corresponding table and class name -        <TableTableName= "Company"Domainobjectname= "Company"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false">            < Propertyname= "Useactualcolumnnames"value= "true" />        </Table>    </Context>    </generatorconfiguration>

Note: In the table if the <table> tag is not configured <property name= "Useactualcolumnnames" value= "true"/> the generated class's properties do not conform to the hump-named rule

Mybatis Reverse Engineering

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.