<?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 ">
<!--configuration Generator--
<generatorConfiguration>
<!--can be used to load configuration items or configuration files, you can use ${propertykey} in the entire configuration file to refer to Configuration Items resource: Configure the resource load address, use RESOURCE,MBG to start from classpath, for example com /myproject/generatorconfig.properties URL: Configure Resources to load geology, using URLs, such as file:///C:/myfolder/generatorConfig.properties. Note that two attributes can be selected only one; In addition, if Mybatis-generator-maven-plugin is used, the properties defined in Pom.xml can be used directly in Generatorconfig.xml <properties Resource= "" Url= ""/>--
<!--when working in MBG, the dependent Package Location property required For additional load indicates the full path of the loaded Jar/zip package
<classpathentry location= "/program files/ibm/sqllib/java/db2java.zip"/>-
<!--context: Generate an Environment ID for a set of objects: required, context ID, used to prompt defaultmodeltype when generating an error: Specifies the style of the build object 1,conditional: Similar to hierarchical, if the table has a primary key, Then the model produces a separate primary key entity class, and if the table has a BLOB field, a separate entity class is generated for the table that contains all the BLOB fields, and then a separate entity class is generated for all the other fields. MBG maintains an inheritance relationship between all generated entity classes.
Obviously the model is more complex. 2,flat: All content (primary key, BLOB) is generated in one object; 3,hierarchical: Primary key generates an Xxkey object (key Class), BLOB, etc., generates an object separately, and other simple attributes are in an object (record Class) TARGETRUNTIME:1,MYBATIS3: Default value that generates content based on mybatis3.x or above, including xxxbysample; 2,mybatis3simple: Similar to MYBATIS3, but does not generate xxxbysample ; Introspectedcolumnimpl: Class fully qualified name for extending MBG
The difference between conditional and hierarchical
Conditional
This is the default value
If an entity class contains only one field, this entity class is not generated separately. Therefore, if a table has a primary key that has only one field, a separate entity class is not generated for that field, and the field is merged into the base entity class.
-
<context id= "MySQL" defaultmodeltype= "flat" targetruntime= "Mybatis3simple" > <!--if written in property does not take effect--
<!--mergeable is true, it can be merged, false, and rebuilt with overlay---
<property name= "mergeable" value= "false" ></property>
<!--automatically identify database keywords, false by default, if set to true, based on the list of keywords defined in sqlreservedwords; general reserved defaults, encountered database keywords (java keyword), using columnoverride overlay-- >
<property name= "Autodelimitkeywords" value= "false"/>
< encoding of Java files generated by!--
<property name= "javafileencoding" value= "UTF-8"/>
<!--formatting Java code--
<property name= "Javaformatter" value= "Org.mybatis.generator.api.dom.DefaultJavaFormatter"/>
<!--formatting XML code--
<property name= "Xmlformatter" value= "Org.mybatis.generator.api.dom.DefaultXmlFormatter"/>
<!--Beginningdelimiter and Endingdelimiter: Indicates that the database is used to tag database object names, such as Oracle is double quotes, and MySQL defaults to ' reverse quotation marks;
<property name= "Beginningdelimiter" value= "'"/>
<property name= "Endingdelimiter" value= "'"/>
<!--must have, use this configuration to link the database @TODO: Whether it can be extended--
<jdbcconnection driverclass= "Com.mysql.jdbc.Driver" connectionurl= "Jdbc:mysql:///pss" userid= "root" password= " Admin ">
<!--This allows you to set property properties, each of which is set to the configured driver-
</jdbcConnection>
<!--java type processors are used to process types in db to type in Java, using Javatyperesolverdefaultimpl by default; Note that by default, you will first try to use Integer,long. Short to correspond to the decimal and numeric data types;
<javatyperesolver type= "Org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl" >
<!--true: use BigDecimal for decimal and numeric data types false: Default, scale>0;length>18: Use BigDecimal; SCALE=0;LENGTH[10,18]: Use long; scale=0;length[5,9]: Use integer; scale=0;length<5: use short;
<property name= "Forcebigdecimals" value= "false"/> </javaTypeResolver>
<!--Java Model Creator, is the necessary element responsible for: 1,key class (see context of Defaultmodeltype); 2,java class; 3, Query class Targetpackage: The package to be put on the generated class, The real package is controlled by the enablesubpackages attribute; Targetproject: Target project, specify an existing directory, the generated content will be placed in the specified directory, if the directory does not exist, MBG will not automatically build the directory--
<javamodelgenerator targetpackage= "Com._520it.mybatis.domain" targetproject= "Src/main/java" >
<!--for mybatis3/mybatis3simple automatically creates a construction method for each generated class that contains all the field, rather than using a setter;
<property name= "constructorbased" value= "false"/>
<!--based on Targetpackage, the database schema is regenerated into a layer of package, the resulting class is placed under this package, the default is false--
<property name= "Enablesubpackages" value= "true"/>
<!--for mybatis3/mybatis3simple whether to create an immutable class, if true, then MBG creates a class that does not have a setter method instead of a class like constructorbased.
<property name= "Immutable" value= "false"/>
<!--set a root object, if the root object is set, then the generated keyclass or Recordclass will inherit the class, and in the table's Rootclass property you can override the option note: If the key class or record Class has the same root class properties, MBG will not regenerate these properties, including: 1, the same property name, the same type, with the same Getter/setter method;
<property name= "Rootclass" value= "Com._520it.mybatis.domain.basedomain"/>
<!--sets whether to call the trim () method on a String type field in the Getter Method--
<property name= "Trimstrings" value= "true"/>
</javaModelGenerator>
<!--generate SQL map XML file generator, note that after Mybatis3, we can use the Mapper.xml file +mapper interface (or not mapper interface), or just mapper interface +annotation, so, If you configure the Javaclientgenerator configuration with the need to generate XML, this element must be configured Targetpackage/targetproject: Same as Javamodelgenerator--
<sqlmapgenerator targetpackage= "Com._520it.mybatis.mapper" targetproject= "Src/main/resources" >
<!--based on Targetpackage, the database schema is regenerated into a layer of package, the resulting class is placed under this package, the default is false--
<property name= "Enablesubpackages" value= "true"/>
</sqlMapGenerator>
<!--for MyBatis, the Mapper interface is generated, note that if the element is not configured, the Mapper interface is not generated by default Targetpackage/targetproject: With Javamodelgenerator Type: Choose how to generate the Mapper interface (under Mybatis3/mybatis3simple): 1,annotatedmapper: Will be generated using the Mapper interface + annotation is created (SQL generated in annotation), the corresponding XML is not generated, 2,mixedmapper: Using a hybrid configuration, a mapper interface is generated and appropriate annotation is added, However, XML is generated in XML; 3,xmlmapper: The Mapper interface is generated, the interface is completely XML-dependent, and note that if the context is mybatis3simple: only Annotatedmapper and Xmlmapper are supported-
<javaclientgenerator targetpackage= "Com._520it.mybatis.mapper" type= "Annotatedmapper" targetProject= "src/main/ Java ">
<!--based on Targetpackage, the database schema is regenerated into a layer of package, the resulting class is placed under this package, the default is false--
<property name= "Enablesubpackages" value= "true"/>
<!--can add a parent interface for all generated interfaces, but MBG is only responsible for generating, not checking
<property name= "Rootinterface" value= ""/>-
</javaClientGenerator>
<!--Select a table to generate the related file, you can have one or more table, and the table must have the table element selected to produce the following files:
1,sql Map File
2, generate a primary key class;
3, except for the Blob and the class of the other fields of the primary key;
4, the class containing the BLOB;
5, a user generated dynamic query condition class (Selectbyexample, Deletebyexample), optional;
6,mapper interface (optional) tableName (necessary): To generate the table name of the object; Note: Case sensitive issues. Normally, MBG will automatically identify the case sensitivity of the database identifier, and in general, MBG will query the data table based on the Schema,catalog or tablename set, as follows:
1, if there is a space in the Schema,catalog or tablename, then what format is set, the exact use of the specified case format to query;
2, otherwise, if the database identifier using uppercase, then MBG automatically turn the table name into uppercase and then find;
3, otherwise, if the database identifier using lowercase, then MBG automatically turn the table name into lowercase and then find;
4, otherwise, use the specified case format query; In addition, if you create a table, use the "" to specify the case of the database object, even if the database identifier is used in uppercase, in this case will also use the given case to create the table name;
This time, please set delimitidentifiers= "true" to preserve the case format; Optional:
1,schema: Database schema;
2,catalog: Catalog of the database;
3,alias: The alias that is set for the data table, and if alias is set, the column name in all of the generated select SQL statements becomes: Alias_actualcolumnname
4,domainobjectname: The name of the generated domain class, if not set, use the table name directly as the domain class name , can be set to Somepck.domainname, then will automatically put the DomainName class into the SOMEPCK package;
5,enableinsert (Default true): Specifies whether to generate INSERT statements;
6,enableselectbyprimarykey (Default true): Specifies whether to generate statements that query objects by primary key (that is, GetByID or get);
7,enableselectbyexample (Default true): Mybatis3simple is false, specifying whether to generate dynamic query statements;
8,enableupdatebyprimarykey (Default true): Specifies whether to generate statements that modify objects by primary key (that is, update);
9,enabledeletebyprimarykey (Default true): Specifies whether to generate statements that delete objects by primary key (that is, delete);
10,enabledeletebyexample (Default true): Mybatis3simple is false to specify whether to generate dynamic Delete statements;
11,enablecountbyexample (Default true): Mybatis3simple is false, specifies whether to generate a dynamic query total number of statements (the total number of bars for paging query);
12,enableupdatebyexample (Default true): Mybatis3simple is false, specifying whether to generate dynamic modification statements (only properties that are not empty in the object are modified);
13,modeltype: Refer to the Defaultmodeltype of the context element, equivalent to coverage;
14,delimitidentifiers: Refer to TableName's explanation, note that the default delimitidentifiers is double quotes, if a database like MySQL is using ' (anti-quote, Then you also need to set the Beginningdelimiter and Endingdelimiter properties of the context)
15,delimitallcolumns: Sets whether the column names in all generated SQL are used with identifiers. The default is False,delimitidentifiers reference context properties Note that many of the parameters in the table are a replication of the default properties of elements such as javamodelgenerator,context;
<table tablename= "UserInfo" >
<!--reference Javamodelgenerator constructorbased Properties--
<property name= "constructorbased" value= "false"/>
<!--defaults to False, and if set to true, the table name will not be added to the catalog or schema in the generated SQL;
<property name= "Ignorequalifiersatruntime" value= "false"/>
<!--reference Javamodelgenerator immutable Properties--
<property name= "Immutable" value= "false"/>
<!--Specifies whether to generate only the domain class, if set to True, only the domain class is generated, and if Sqlmapgenerator is also configured, only resultmap elements are generated in the mapper XML file--
<property name= "Modelonly" value= "false"/>
<!--reference Javamodelgenerator Rootclass properties <property name= "Rootclass" value= ""/>--
<!--reference Javaclientgenerator rootinterface properties <property name= "Rootinterface" value= ""/>--
<!--if Runtimecatalog is set, then in the generated SQL, the specified catalog is used instead of the catalog <property name= "Runtimecatalog" value= on the Table element ""/>--
<!--if Runtimeschema is set, the specified schema is used in the generated SQL instead of the schema <property on the table element name= "Runtimeschema" value= "/ >
<!--if Runtimetablename is set, the specified tablename is used in the generated SQL instead of TableName <property name= "on the Table element" Runtimetablename "value=" "/>--
<!--Note that this property is useful only for mybatis3simple, and if the runtime chosen is Mybatis3simple, a SelectAll method is generated, and if Selectallorderbyclause is specified, Then the specified order condition is added to the SQL;
<property name= "Selectallorderbyclause" value= "Age desc,username ASC"/>
<!--If set to true, the generated model class will use the name of the column itself without using the hump naming method, such as Born_date, and the generated property name is Born_date, not borndate--
<property name= "Useactualcolumnnames" value= "false"/>
<!--Generatedkey is used to generate a method for generating a primary key, and if the element is set, MBG generates a correct <selectKey> element in the generated <insert> element, which is optional column: The name of the primary key; SQLStatement: The Selectkey statement to be generated has the following options: Cloudscape: SQL equivalent to Selectkey: VALUES identity_val_local ()
DB2: SQL equivalent to Selectkey: VALUES identity_val_local ()
DB2_MF: SQL equivalent to Selectkey: SELECT identity_val_local () from SYSIBM. SYSDUMMY1
Derby: SQL equivalent to Selectkey: VALUES identity_val_local ()
HSQLDB: SQL equivalent to Selectkey: Call IDENTITY ()
Informix: SQL equivalent to Selectkey: Select Dbinfo (' Sqlca.sqlerrd1 ') from Systables where tabid=1
MYSQL: SQL equivalent to Selectkey: select LAST_INSERT_ID () SQL Server: Selectkey equivalent to: Select Scope_identity ()
SYBASE: SQL equivalent to Selectkey: SELECT @ @IDENTITY
JDBC: equivalent to adding usegeneratedkeys= "true" and Keyproperty property on the generated Insert element <generatedkey column= "" sqlstatement= ""/>-- >
<!--This element renames the column name before calculating the object property name based on the column name in the table, which is well suited for use in tables where the column has a common prefix string, such as the column name: Cust_id,cust_name,cust_email,cust_address, etc.; Then you can set SearchString to "^cust_" and replace with whitespace, then the property name in the generated customer object is not custid,custname, etc., but instead is replaced with Id,name,email first, then the property: ID, Name,email, note that MBG uses JAVA.UTIL.REGEX.MATCHER.REPLACEALL to replace SearchString and replacestring, and if columnoverride elements are used, The property is not valid;
-
<columnrenamingrule searchstring= "" replacestring= ""/>
<!--is used to modify the properties of a column in a table, MBG uses the modified column to generate the properties of the domain; columns: the name of the list to be reset; Note that there can be more than one columnoverride element in a TABLE element----
<columnoverride column= "username" >
<!--use property properties to specify the name of the property to be generated by the column--
<property name= "Property" value= "UserName"/>
<!--Javatype is used to specify the property type of the generated domain, using the fully qualified name of the type <property name= "Javatype" value= ""/>-
<!--Jdbctype is used to specify the JDBC type of the column <property name= "Jdbctype" value= ""/>-
<!--Typehandler is used to specify the Typehandler that the column uses, and if you want to specify a fully qualified name for the configuration type processor, note that MyBatis is not generated into Mybatis-config.xml Typehandler will only generate similar:
The parameter description of where id = #{id,jdbctype=bigint,typehandler=com._520it.mybatis.mytypehandler} <property name= "JdbcType" Value= ""/>--
<!--refer to the Delimitallcolumns configuration of the table element, which defaults to False <property name= "Delimitedcolumnname" value= ""/>-
</columnOverride>
<!--Ignorecolumn set a column that is MGB ignored, if the column is set, in the generated domain, there will be no columns in the generated SQL: Specifies the name of the column to ignore; Delimitedcolumnname: Refer to the Delimitallcolumns configuration of the table element, default to False note that there can be multiple ignorecolumn elements in a TABLE element
<ignorecolumn column= "DeptID" delimitedcolumnname= ""/>-
</table>
</context>
</generatorConfiguration>
MyBatis Generator XML Configuration Reference