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