With reverse engineering, single-table additions and deletions and related entity classes, as well as attribute comments do not have to write their own, can be automated generation, only the following three steps can be
The advantages of reverse engineering are: automatic generation of entity classes and corresponding additions and deletions, efficiency relative to the previous personal development of a write and delete to be higher than the search
The disadvantage of reverse engineering is that SQL statements in XML are added to MyBatis's own dynamic SQL and a lot of judgments, which is difficult for people who are not very skilled in dynamic SQL.
Note: After a successful run, remember to refresh, otherwise you will not see
First, the Guide package (the following package guide, success 80%)
Second, create a new Generator.xml file, configure
<?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><ContextId= "Testtables"Targetruntime= "MyBatis3"><PropertyName= "Javafileencoding"Value= "UTF-8"/><Commentgenerator><!--Whether to remove automatically generated comments true: Yes: false: No-<PropertyName= "Suppressallcomments"Value= "true"/></Commentgenerator><!--Database connection information: Driver class, connection address, user name, password-<JdbcconnectionDriverclass= "Com.mysql.jdbc.Driver"Connectionurl= "Jdbc:mysql://localhost:3306/pms"Userid= "Root"Password= "1234"></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 when True-<Javatyperesolver><PropertyName= "Forcebigdecimals"Value= "false"/></Javatyperesolver><!--Targetproject: Generating the location of the model class-<JavamodelgeneratorTargetpackage= "Cn.pms.model"Targetproject= ". \src"><!--Enablesubpackages: Do you want the schema to be the suffix of the package-<PropertyName= "Enablesubpackages"Value= "false"/><!--The space returned from the database before and after the value is cleaned-<PropertyName= "Trimstrings"Value= "true"/></Javamodelgenerator><!--Targetproject:mapper the location of the map file generation-<SqlmapgeneratorTargetpackage= "Mapper"Targetproject= ". \src"><!--Enablesubpackages: Do you want the schema to be the suffix of the package-<PropertyName= "Enablesubpackages"Value= "false"/></Sqlmapgenerator><!--Targetpackage:mapper the location generated by the interface-<JavaclientgeneratorType= "Xmlmapper"Targetpackage= "Cn.pms.mapper"Targetproject= ". \src"><!--Enablesubpackages: Do you want the schema to be the suffix of the package-<PropertyName= "Enablesubpackages"Value= "false"/></javaclientgenerator> <!-- Specify database table --> < table schema= "" Tablename= "Hotel" Domainobjectname= "Hotel" ></ table> </context></generatorconfiguration>
Third, write Test class
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;PublicClassGeneratorsqlmap {Publicvoid Generator ()Throwsexception{list<string> warnings =New arraylist<string>();Boolean overwrite =True;//Specify reverse engineering profile file ConfigFile =New File ("Src/generatorconfig.xml"); Configurationparser CP =NewConfigurationparser (warnings); Configuration config =Cp.parseconfiguration (ConfigFile); Defaultshellcallback callback =new defaultshellcallback (overwrite); Mybatisgenerator mybatisgenerator = new mybatisgenerator (config, callback, warnings); Mybatisgenerator.generate (null);} public static void Main (string[] args) throws Exception { try {Generatorsqlmap generators Qlmap = new generatorsqlmap (); Generatorsqlmap.generator ();} Catch (Exception e) {e.printstacktrace (); }}}
Four, after the operation of the results shown that the success of the
Dynamic Web project of MyBatis reverse engineering