I haven't done a project recently, so I have reorganized the most complete configuration file for the most complete Mybatis Generator (MBG for short), with detailed explanations, and I no longer have to look at EN's User Guide;
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE generatorConfigurationPUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"><!-- Configuration generator--><generatorConfiguration><!-- It can be used to load configuration items or configuration files. In the entire configuration file, you can use ${propertyKey} to reference the configuration item resource: configure the resource loading address, use resource, and MBG starts from classpath, such as com/myproject/generatorConfig.properties url: configure resource loading geology, use URL, such as file:///C:/myfolder/generatorConfig.properties. Note that only one of the two properties can be selected; in addition, if mybatis-generator-maven-plugin is used, then the properties defined in pom.xml can be used directly in generatorConfig.xml <properties resource="" url="" />--><!-- When MBG works, the location attribute of the dependency package that needs to be loaded indicates the full path to load the jar/zip package<classPathEntry location="/Program Files/IBM/SQLLIB/java/db2java.zip" />--><!-- context: The environment id for generating a group of objects: Required, context id, used to prompt when generating an error defaultModelType: Specify the style of the generated object 1, conditional: similar to hierarchical; 2, flat: all content (primary key, blob), etc. are generated in one object; 3, hierarchical: the primary key generates an XXKey object (key class), blob, etc. generates an object separately, and other simple attributes are in one object (record class)targetRuntime:1, MyBatis3: The default value, generates content based on MyBatis3.x and above versions, including XXXBySample; 2, MyBatis3Simple: Similar to MyBatis3, but does not generate XXXBySample; introducedColumnImpl: The fully qualified name of the class, used to extend MBG--><context id="mysql" defaultModelType="hierarchical" targetRuntime="MyBatis3Simple" ><!-- Automatically identify database keywords, default false, if set to true, according to the keyword list defined in SqlReservedWords; generally retain the default value, encounter database keywords (Java keywords), use columnOverride to override --><property name="autoDelimitKeywords" value="false"/><!-- Encoding of generated Java files--><property name="javaFileEncoding" value="UTF-8"/><!-- Format java code--><property name="javaFormatter" value="org.mybatis.generator.api.dom.DefaultJavaFormatter"/><!-- Format XML code--><property name="xmlFormatter" value="org.mybatis.generator.api.dom.DefaultXmlFormatter"/><!-- beginningDelimiter and endingDelimiter: Specify the symbols used to mark the database object name. For example, ORACLE is double quotes, and MYSQL defaults to `backticks; --><property name="beginningDelimiter" value="`"/><property name="endDelimiter" value="`"/><!-- You must have it, use this configuration to link the database @TODO: Can it be extended--><jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql:///pss" userId="root" password="admin"><!-- Here you can set property properties, and each property property is set to the configured Driver--></jdbcConnection><!-- The java type processor is used to process types in DB to types in Java, and JavaTypeResolverDefaultImpl is used by default; note that by default, you will try to use Integer, Long, Short, etc. to correspond to 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><!-- The java model creator is the necessary elements responsible: 1. key class (see context's defaultModelType); 2. Java class; 3. Query class targetPackage: The package to be placed in the generated class, the real package is controlled by the enableSubPackages attribute; targetProject: The target project, specify an existing directory, and the generated content will be placed in the specified directory. If the directory does not exist, MBG will not automatically create a directory--><javaModelGenerator targetPackage="com._520it.mybatis.domain" targetProject="src/main/java"><!-- for MyBatis3/MyBatis3Simple automatically creates a constructor for each generated class, which contains all fields; instead of using setters; --><property name="constructorBased" value="false"/><!-- Based on the targetPackage, a layer of package is generated according to the database schema. The final generated class is placed under this package, and the default is false --><property name="enableSubPackages" value="true"/><!-- for MyBatis3/MyBatis3Simple creates an immutable class? If true, MBG will create a class without a setter method, and replace it with a class similar to constructorBased--><property name="immutable" value="false"/><!-- Set a root object. If this root object is set, the generated keyClass or recordClass will inherit this class; this option can be overridden in the rootClass property of Table Note: If there are the same attributes as root class in the key class or record class, MBG will not regenerate these attributes, including: 1. The attribute name is the same, the same type, and the same getter/setter method; --><property name="rootClass" value="com._520it.mybatis.domain.BaseDomain"/><!-- Set whether to call the trim() method on the String type field in the getter method--><property name="trimStrings" value="true"/></javaModelGenerator><!-- XML file generator for generating SQL maps. Note that after Mybatis3, we can use mapper.xml file + Mapper interface (or do not use mapper interface), or only use Mapper interface + Annotation. Therefore, if the javaClientGenerator configuration needs to generate XML, this element must be configured with targetPackage/targetProject: same as javaModelGenerator--><sqlMapGenerator targetPackage="com._520it.mybatis.mapper" targetProject="src/main/resources"><!-- Based on the targetPackage, a layer of package is generated according to the database schema. The final generated class is placed under this package, and the default is false --><property name="enableSubPackages" value="true"/></sqlMapGenerator><!-- For mybatis, it is to generate a mapper interface. Note that if the element is not configured, the mapper interface will not be generated by default targetPackage/targetProject: same as javaModelGeneratortype: Choose how to generate a mapper interface (under MyBatis3/MyBatis3Simple): 1. ANNOTATEDMAPPER: It will generate a mapper interface using Mapper interface + Annotation (SQL generated in a In nnotation), the corresponding XML will not be generated; 2. MIXEDMAPPER: Using a hybrid configuration, the Mapper interface will be generated and the appropriate Annotation will be added appropriately, but the XML will be generated in XML; 3. XMLMAPPER: The Mapper interface will be generated, and the interface will completely depend on XML; Note that if the context is MyBatis3Simple: Only ANNOTATEDMAPPER and XMLMAPPER--><javaClientGenerator targetPackage="com._520it.mybatis.mapper" type="ANNOTATEDMAPPER" targetProject="src/main/java"><!-- Based on the targetPackage, a layer of package is generated according to the database schema. The final generated class is placed under this package, which defaults to false --><property name="enableSubPackages" value="true"/><!-- You can add a parent interface to all generated interfaces, but MBG is only responsible for generation and is not responsible for checking <property name="rootInterface" value=""/>--></javaClientGenerator><!-- Select a table to generate related files. There can be one or more tables. There must be a table selected by the table element. The following files will be generated: 1. SQL map file 2. Generate a primary key class; 3. Classes with other fields except BLOB and primary key; 4. Classes containing BLOB; 5. A conditional class for users to generate dynamic queries (selectByExample, deleteByExample), optional; 6. Mapper interface (optional) tableName (necessary): The table name of the object to be generated; Note: case sensitive issues. Under normal circumstances, MBG will automatically identify the case sensitivity of the database identifier. In general, MBG will query the data table based on the set schema, catalog or tablename, and follow the following process: 1. If there are spaces in the schema, catalog or tablename, then the format set is accurately used to query; 2. Otherwise, if the database identifier is capitalized, then MBG will automatically turn the table name into capital and then search; 3. Otherwise, if the database identifier is capitalized, then MBG will automatically turn the table name into capital and then search; Search; 4. Otherwise, use the specified case format to query; in addition, if the database object is used when creating a table, the table name will be created using the given case even if the database identifier is used, in this case, please set the delimitIdentifiers="true" to retain the case format; optionally: 1. schema: the schema of the database; 2. catalog: the database catalog; 3. alias: the alias set for the data table. If alias is set, then all SELECTs generated In SQL statements, the column name will become: alias_actualColumnName4, domainObjectName: The name of the generated domain class. If not set, use the table name as the name of the domain class; it can be set to somepck.domainName, then the domainName class will be automatically placed in the somepck package; 5, enableInsert (default true): Specify whether to generate insert statement; 6, enableSelectByPrimaryKey (default true): Specify whether to generate the Statement for querying the object according to the primary key (i.e. getById or get); 7. enableSelectByExample (default true): MyBatis3Simple is false, specifying whether to generate dynamic query statements; 8. enableUpdateByPrimaryKey (default true): specifying whether to generate a statement that modifies the object according to the primary key (i.e. update); 9. enableDeleteByPrimaryKey (default true): specifying whether to generate a statement that deletes the object according to the primary key (i.e. delete); 10. enableDel eteByExample (default true): MyBatis3Simple is false, specify whether to generate dynamic delete statements; 11, enableCountByExample (default true): MyBatis3Simple is false, specify whether to generate dynamic query total number of words (used for total number of words for pagination); 12, enableUpdateByExample (default true): MyBatis3Simple is false, specify whether to generate dynamic modification statements (only modify attributes that are not empty in the object); 13, modelTyp e: Refer to the defaultModelType of the context element, which is equivalent to overwriting; 14, delimitIdentifiers: Refer to the explanation of tableName, note that the default delimitIdentifiers are double quotes. If a database like MYSQL uses ` (backquotes, then you also need to set the context's beginningDelimiter and endDelimiter properties) 15, delimitAllColumns: Set whether all generated column names in SQL are caused by identifiers. DelimitIdentifiers refer to the property of context. Note that many parameters in the table are a repetition of the default properties of javaModelGenerator, context and other elements; --><table tableName="userinfo" ><!-- Reference the constructorBased property of javaModelGenerator--><property name="constructorBased" value="false"/><!-- Default is false. If set to true, the table name will not be added with catalog or schema in the generated SQL; --><property name="ignoreQualifiersAtRuntime" value="false"/><!-- Reference javaModelGenerator The immutable property of the immutable property --><property name="immutable" value="false"/><!-- Specifies whether to generate only the domain class. If set to true, only the domain class is generated. If the sqlMapGenerator is also configured, then in the mapper XML file, only the resultMap element is generated--><property name="modelOnly" value="false"/><!-- Refer to the rootClass property of the javaModelGenerator<property name="rootClass" value=""/>--><!-- Refer to the rootInterface property of the javaClientGenerator<property name="rootInterface" value=""/>--><!-- Refer to the rootInterface property of the javaClientGenerator<property name="rootInterface" value=""/>--><!-- If runtimeCatalog is set, then in the generated SQL, the specified catalog is used instead of the catalog on the table element. <property name="runtimeCatalog" value=""/>--><!-- If runtimeSchema is set, then in the generated SQL, the specified schema is used instead of the schema on the table element. <property name="runtimeSchema" value=""/>--><!-- If runtimeTableName is set, then in the generated SQL, the specified tablename is used instead of the table element. <property name="runtimeTableName" value=""/>--><!-- Note that this property is only useful for MyBatis3Simple; if the selected runtime is MyBatis3Simple, a SelectAll method will be generated. If selectAllOrderByClause is specified, the specified order condition will be added to the SQL; --><property name="selectAllOrderByClause" value="age desc,username asc"/><!-- If set to true, the generated model class will directly use the column itself name, and will no longer use camel naming methods, 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. If this element is set, the MBG will generate a correct <selectKey> element in the generated <insert> element. The element can be selected column: the column name of the primary key; sqlStatement: The selectKey statement to be generated has the following options: Cloudscape: The SQL equivalent to selectKey is: VALUES IDENTITY_VAL_LOCAL()()DB2: The SQL equivalent to selectKey is: VALUES IDENTITY_VAL_LOCAL()()DB2_MF: The SQL equivalent to selectKey is: SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1Derby: The SQL equivalent to selectKey is: VALUES IDENTITY_VAL_LOCAL() HSQLDB: The SQL equivalent to selectKey is: CALL IDENTITY()Informix: The SQL equivalent to selectKey is: select dbinfo('sqlca.sqlerrd1') from systables where tabid=1MySql: The SQL equivalent to selectKey is: SELECT LAST_INSERT_ID()SqlServer : The SQL equivalent to selectKey is: SELECT SCOPE_IDENTITY()SYBASE : The SQL equivalent to selectKey is: SELECT @@IDENTITYJDBC : It is equivalent to adding useGeneratedKeys="true" and keyProperty attributes on the generated insert element<generatedKey column="" sqlStatement=""/>--><!-- This element will rename the column name before calculating the object attribute name based on the column name in the table. It is very suitable for when the columns in the table have common prefix strings, such as the column name: CUST_ID, CUST_NAME, CUST_EMAIL, CUST_ADDRESS, etc.; then you can set the searchString to "^CUST_" and replace it with blank space. Then the attribute name in the generated Customer object is not custId, cu stName, etc., but is replaced with ID, NAME, EMAIL, and then becomes attributes: id, name, email; note that MBG uses java.util.regex.Matcher.replaceAll to replace searchString and replaceString. If the columnOverride element is used, this attribute is invalid; <columnRenamingRule searchString="" replaceString=""/>--><!-- Used to modify the properties of a column in the table. MBG will use the modified column to generate the properties of the domain; column: the column name to be reset; note that there can be multiple columnOverride elements in a table element~--><columnOverride column="username"><!-- Use property attribute to specify the attribute name to generate the column--><property name="property" value="userName"/><!-- javaType is used to specify the attribute type of the generated domain, and the fully qualified name of the type is used. <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 used in this column. If you want to specify, please note that in mybatis, the typeHandler in mybatis-config.xml will not be generated in mybatis-config.xml, only the parameter description of the following: where id = #{id,jdbcType=BIGINT,typeHandler=com._520it.mybatis.MyTypeHandler}<property name="jdbcType" value=""/>--><!-- Refer to the delimitAllColumns configuration of the table element, default is false<property name="delimitedColumnName" value=""/>--></columnOverride><!-- ignoreColumn sets a column that MGB ignores. If a re-column is set, then in the generated domain and generated SQL, column: specifies the name of the column to be ignored; delimitedColumnName: Refer to the delimitAllColumns configuration of the table element, default is false. Note that there can be multiple ignoreColumn elements in a table element<ignoreColumn column="deptId" delimitedColumnName=""/>--></table></context></generatorConfiguration>The above is the detailed explanation of the most perfect configuration file of Mybatis Generator introduced to you by the editor (full version). I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!