MyBatis Generator Perfect configuration file (full version) _java

Source: Internet
Author: User
Tags generator numeric lowercase java keywords

Recently did not do the project, the reorganization of a most complete MyBatis generator (MBG) The most complete configuration file, with detailed, no longer to see en's User Guide;

<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis generator Configuration" "1.0//en Mybatis.org/dtd/mybatis-generator-config_1_0.dtd > <!--configuration builder--> <generatorConfiguration> <!-- Can be used to load configuration items or configuration files, you can use ${propertykey} in the entire configuration file to refer to the Configuration Item resource: Configure the resource load address, use RESOURCE,MBG to start looking from classpath, such as com/
Myproject/generatorconfig.properties URL: Configure Resources to load geology, using URLs in the way, such as file:///C:/myfolder/generatorConfig.properties.
Note that two attributes can only be selected for one; In addition, if Mybatis-generator-maven-plugin is used, properties defined in Pom.xml can be used directly in Generatorconfig.xml <properties Resource= "Url=" "/>--> <!--when working at MBG, the dependent package location properties that need to be loaded indicate the full path to load Jar/zip package <classpathentry location="/
Program Files/ibm/sqllib/java/db2java.zip '/>--> <!--context: Generating an Environment ID for a set of objects: required, contextual ID, for prompting when an error is generated
Defaultmodeltype: Specifies the style of the generated object 1,conditional: similar to hierarchical; 2,flat: All content (primary key, BLOB) is generated in one object; 3,hierarchical: The primary key generates a Xxkey object (key Class), a blob, and so on, generates one object individually, and other simple attributes are in one object (record CLass) TARGETRUNTIME:1,MYBATIS3: Default value that generates content based on mybatis3.x above, including xxxbysample; 2,mybatis3simple: Similar to MYBATIS3, Simply does not generate Xxxbysample Introspectedcolumnimpl: Class fully qualified name for extended MBG--> <context id= "MySQL defaultmodeltype=" hierarchical "Targetruntime=" Mybatis3simple > <!--automatically recognize database keywords, default false, and if set to true, according to the list of keywords defined in sqlreservedwords; Generally, leave the defaults Database keywords (Java keywords) are encountered, using Columnoverride to overwrite--> <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: Indicates a database symbol for marking database object names, such as Oracle is double quotes, MySQL defaults to ' inverted quotes;--> <property name= ' Beginningdelimiter "value=" "/> <property name=" endingdelimiter "value=" "/> <!--must have, use this configuration to link the database @TODO : Whether you can extend
--> <jdbcconnection driverclass= "Com.mysql.jdbc.Driver" connectionurl= "Jdbc:mysql:///pss" userid= "root" password= "Admin" > <!--this can be set property properties, each property attribute is set to the configured driver--> </jdbcConnection> <!-- Java type processors are used to work with types in db for types in Java, using Javatyperesolverdefaultimpl by default; Note that by default, you will try to use Integer,long,short to correspond to decimal and numeric data type;--> <javatyperesolver type= "Org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl"
> <!--true: use BigDecimal to correspond to the decimal and numeric data types false: Default, scale>0;length>18: Use BigDecimal; SCALE=0;LENGTH[10,18]: using Long; scale=0;length[5,9]: Using Integer; scale=0;length<5: using Short;--> <property name= "Forcebigdecimals" value= "false"/> </javaTypeResolver> <!--java Model Builder, is responsible for the elements that must be: 1,
Key class (see context Defaultmodeltype); 2,java Class 3, query class Targetpackage: The generated class to put the package, the real package is controlled by the enablesubpackages attribute; Targetproject: Target project, specifies a directory in existence, the generated content is placed in the specified directory, and if the directory does not exist, MBG does not automatically build the 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 the field, rather than using a setter;--> <property name= "constructorbased" value= "false"/> <!--on the basis of targetpackage, it is regenerated into a layer of package based on the schema of the database. The resulting class is placed under this package, default to False--> <property name= "Enablesubpackages" value= "true"/> <!--for MYBATIS3/ Mybatis3simple whether to create an immutable class, if true, then 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 the root object is set, then the generated Keyclass or Recordclass inherits the class You can override this option in the Rootclass property of the table note: If you have the same attribute in key class or record class with Root class, MBG will not regenerate these properties, including: 1, same property name, same type, Have the same Getter/setter method;--> <property name= "Rootclass" value= "Com._520it.mybatis.domain.basedomain"/> <!-- Set whether the trim () method is invoked on a String type field in the Getter method--> <property name= "trimstrings" value= "true"/>
Javamodelgenerator> <!--generate the XML file builder for SQL map, note that after Mybatis3, we can use Mapper.xml file +mapper interface (or not mapper interface). or only use the Mapper interface +annotation, so asThe Javaclientgenerator configuration is configured with the need to generate XML, this element must be configured with Targetpackage/targetproject: Javamodelgenerator--> < Sqlmapgenerator targetpackage= "Com._520it.mybatis.mapper" targetproject= "src/main/resources" > <!-- On the basis of targetpackage, according to the database schema regenerated into a layer of package, the final generated class placed under this package, default to 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: Same Javamodelgenerator type: Choose how to generate the Mapper interface (under Mybatis3/mybatis3simple): 1,annotatedmapper: Creates a method that uses the Mapper interface +annotation (SQL build in annotation) and does not generate the corresponding XML; 2,mixedmapper: Use a mixed configuration to generate the Mapper interface , and appropriately add the appropriate annotation, but the XML is generated in XML; 3,xmlmapper: The Mapper interface is generated, the interface is completely dependent on XML; If the context is mybatis3simple: only support Annotatedmapper and Xmlmapper--> <javaclientgenerator targetpackage= "com._ 520it.mybatis.mapper "type=" Annotatedmapper "targetproject=" Src/main/java "> <!--on the basis of Targetpackage, Based on the schema regeneration of the database into a layer of package, the resulting class is placed under this package, default to False--> <property NAMe= "Enablesubpackages" value= "true"/> <!--can add a parent interface for all generated interfaces, but MBG is responsible for generating only, not checking <property name= "
Rootinterface "value="/>--> </javaClientGenerator> <!--Select a table to generate related files, you can have one or more table, you must have a TABLE element The selected table generates a file: 1,sql Map file 2, generating a primary key class, 3, except for BLOBs and other fields of primary keys, 4, classes containing BLOBs, and 5, a user-generated conditional class for dynamic queries (Selectbyexample, Deletebyexample), optional, 6,mapper interface (optional) tablename (necessary): The table name to generate the object; Note: Case sensitive issue. Normally, MBG will automatically identify the case sensitivity of the database identifier, and in general, MBG will query the data table according to the set Schema,catalog or tablename, according to the following procedure: 1, if schema, There are spaces in the catalog or tablename, so what format is set, on the exact use of the specified case format to query; 2, otherwise, if the identifier of the database is capitalized, then MBG automatically turns the table name into uppercase and then searches for 3, otherwise, if the identifier of the database uses lowercase, Then MBG automatically turns the table name into lowercase and finds it again; 4, otherwise, queries are used in the specified case format, and if the table is created, the database object is case-sensitive, even if the database identifier is capitalized, and in this case the table name is created using the given case; Set delimitidentifiers= "true" to preserve the case format; Optional: 1,schema: Schema of the database; 2,catalog: Database catalog; 3,alias: An alias set for a datasheet, If you set the alias, the column name becomes: Alias_actualcolumnname 4,domainobjectname: The name of the generated domain class, if not set, in all select SQL statements that are generated. Use the table name directly as the domain class name, and can be set to Somepck.domainname, then automatically put the DomainName class into the SOMEPCK package; 5,Enableinsert (Default true): Specifies whether to generate an INSERT statement; 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 to False to specify whether dynamic query statements are generated;
8,enableupdatebyprimarykey (Default true): Specifies whether to generate a statement that modifies the object according to the primary key (that is, update);
9,enabledeletebyprimarykey (Default true): Specifies whether to generate a statement that deletes an object by primary key (that is, delete);
10,enabledeletebyexample (Default true): Mybatis3simple to False to specify whether dynamic deletion statements are generated;
11,enablecountbyexample (Default true): Mybatis3simple to False, specifies whether to generate a dynamic query Total bar statement (the total number of pages used for paging query);
12,enableupdatebyexample (Default true): Mybatis3simple to False to specify whether to generate dynamic modification statements (modify only attributes that are not NULL in the object); 13,modeltype: Reference to the Defaultmodeltype of the context element, equivalent to coverage; 14,delimitidentifiers: Reference tablename explanation, note,
The default delimitidentifiers is double quotes, if a database like MySQL uses ' (inverted quotes, then you need to set the context's Beginningdelimiter and Endingdelimiter attributes) 15,delimitallcolumns: Sets whether the column names in all generated SQL are used by 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 Javamodelgenerator,context elements;--> < Table Tablename= "UserInfo" > <!--reference javamodelgenerator constructorbased properties--> <property name= "constructorBased "value= false"/> <!--defaults to False, and if set to true, the table name does not add catalog or schema to the generated SQL;--> <property name= " Ignorequalifiersatruntime "value=" false "/> <!--reference Javamodelgenerator immutable properties--> <property name=" Immutable "value= false"/> <!--Specifies whether the domain class is generated only, if set to True, only the domain class is generated, and if Sqlmapgenerator is configured, then in the Mapper XML file, Generates only the Resultmap element--> <property name= "Modelonly" value= "false"/> <!--reference Javamodelgenerator Rootclass Properties <p Roperty 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 < on the table element. Property Name= "Runtimecatalog" value= "/>--> <!--if Runtimeschema is set, then in the generated SQL, the specified schema is used, Instead of schema <property name= on the Table element "Runtimeschema" value= "/>--> <!--if Runtimetablename is set, then in the generated SQL, Use the specified tablename instead of the TableName <property on the Table element name= "Runtimetablename" value= ""/&Gt --> <!--Note that this property is only useful for mybatis3simple, and if the runtime selected is Mybatis3simple, then a SelectAll method is generated. If Selectallorderbyclause is specified, the specified order condition is added to the SQL;--> <property name= "Selectallorderbyclause" age Desc,username asc "/> <!--If set to true, the generated model class will directly use the name of the column itself, without using the hump naming method, such as Born_date, where the generated property name is Born_date,
Instead of Borndate--> <property name= "Useactualcolumnnames" value= "false"/> <!--Generatedkey is used to generate a method that generates a primary key. If this element is set, MBG generates a correct <selectKey> element in the generated <insert> element, optionally column: The column name of the primary key; SQLStatement: The Selectkey statement to generate.
The following options are available: Cloudscape: equivalent to Selectkey sql: Values Identity_val_local () DB2: equivalent to Selectkey sql: Values Identity_val_local () DB2_MF: The equivalent of Selectkey SQL is: SELECT identity_val_local () from SYSIBM. SYSDUMMY1 Derby: The equivalent of Selectkey SQL is: VALUES identity_val_local () HSQLDB: the equivalent of Selectkey sql: Call IDENTITY () Informix: The equivalent of Selectkey SQL is: Select Dbinfo (' Sqlca.sqlerrd1 ') from Systables where tabid=1 MySql: SQL equivalent to Selectkey: select Last_ INSERT_ID () SQL Server: the equivalent of Selectkey is: SELect scope_identity () SYBASE: the equivalent of Selectkey SQL is: SELECT @ @IDENTITY JDBC: equivalent to adding usegeneratedkeys= "true" on the generated Insert element and Keyproperty Properties <generatedkey column= "sqlstatement="/>--> <!--The element renames the column name before the object property name is computed based on the column name in the table. Ideal for use when a column in a table has a common prefix string, such as a column named: cust_id,cust_name,cust_email,cust_address, then you can set SearchString to "^cust_" and use whitespace replacement, The property name in the generated customer object is not custid,custname, but is replaced by the Id,name,email and then the attribute: id,name,email; note that MBG uses JAVA.UTIL.REGEX.MATCHER.REPLACEALL to replace SearchString and replacestring, which is not valid if the columnoverride element is used; < Columnrenamingrule searchstring= "replacestring="/>--> <!--to modify the properties of a column in a table, MBG will use the modified column to generate domain properties; column : The column name to reset; Note that there can be multiple columnoverride elements in a TABLE element ha ~--> <columnoverride column= "username" > <!-- Use property properties to specify the name of the property to be generated by the column--> <property name= "Properties" 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 to specify the JDBC type for the column <property name= "Jdbctype" value= "/>--&GT
<!--Typehandler is used to specify the Typehandler to use for this column, and if you want to specify that the fully qualified name of the configuration type processor is noted, MyBatis will not be generated in Mybatis-config.xml Typehandler Only a parameter description like: where id = #{id,jdbctype=bigint,typehandler=com._520it.mybatis.mytypehandler} is generated <property name= " Jdbctype "value=" "/>--> <!--reference TABLE element delimitallcolumns configuration, default to False <property Name=" Delimitedcolumnname "Value=" "/>--> </columnOverride> <!--ignorecolumn sets a column that is ignored by MGB, and if a column is set, in the generated SQL in the resulting domain, None of the columns will appear column: Specifies the name of the column to ignore; Delimitedcolumnname: Reference Table element Delimitallcolumns configuration, default to False note,
There can be multiple ignorecolumn elements in a TABLE element <ignorecolumn column= "DeptID" delimitedcolumnname= ""/>--> </table> </context> </generatorConfiguration>

The above is a small series to introduce the MyBatis generator the most perfect configuration file details (full version), I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.