MyBatis Reverse engineering--mybatis Generator (MBG)-Configuration file detailed (2)

Source: Internet
Author: User
Tags comments generator numeric table name

Reprint Address: Mybatis Generator (abbreviation MBG) The most complete configuration file

Other points of note: (i) <context> elements

Used to specify the environment that generates a set of objects

(1) Targetruntime: Run-time target for specifying generated code

MyBatis3: Default luxury Edition

mybatis3simple: simple version of Crud (ii) attribute

<!--automatically identify database keywords, default false, if set to true, based on the list of keywords defined in sqlreservedwords,
        and generally keep the default values, the database keyword (Java keyword) is encountered, Use Columnoverride Overlay--
    <property name= "Autodelimitkeywords" value= "false"/>
    <!-- Generated Java files are encoded--
    <property name= "javafileencoding" value= "UTF-8"/>
    <!--formatted Java code
    -- <property name= "Javaformatter" value= "Org.mybatis.generator.api.dom.DefaultJavaFormatter"/>
    <!-- Formatted XML code--
    <property name= "Xmlformatter" value= "Org.mybatis.generator.api.dom.DefaultXmlFormatter"/ >

    <!--beginningdelimiter and Endingdelimiter: Indicates that the database has symbols used to tag database object names, such as Oracle is double quotes, and MySQL defaults to ' anti-quote;
    <property name= "Beginningdelimiter" value= "'"/>
    <property name= "Endingdelimiter" value= "'"/>
(c) <javaTypeResolver> elementsUsed to specify whether MyBatis generator should force the use of Java.math.BigDecimal as the decimal and numeric fields, instead of replacing the integral type when possible
<javatyperesolver >
			<property
				name= "forcebigdecimals"
				value= "true"/>
		</ Javatyperesolver>
True: If the database column is of type decimal or numeric, the Java type Resolver will always use Java.math.BigDecimal. False: The default value. The substitution rules are as follows: If the scale is greater than 0, or the length is greater than 18, the Java.math.BigDecimal type will be used if the scale is zero and the length is 10 to 18, then the Java type Resolver will replace the Java.lang.Long. If the scale is zero and the length is 5 to 9, then the Java type Parser overrides Java.lang.Integer. If the scale is zero and the length is less than 5, the Java type Resolver overrides Java.lang.Short.
(d) <javaModelGenerator> elementsJava Model Builder

(1) Targetpackage: The generated class will be placed in the package

(2) Targetproject: Specifies the target project, the path to the class, for the generated object. Generally for. \src. Maven for. \src\main\java.

Final file path Wetargetprojecttargetpackage

(3) Other sub-tags

<javamodelgenerator targetpackage= "Com._520it.mybatis.domain" targetproject= "Src/main/java" > <!--for My Batis3/mybatis3simple automatically creates a construction method for each generated class that contains all the field, not the setter;--<property Nam E= "constructorbased" value= "false"/> <!--in targetpackage based on the database schema regenerated into a layer of package, the resulting class is placed under this package, the default False--<property name= "Enablesubpackages" value= "true"/> <!--for mybatis3/mybatis3simp
        If Le creates an immutable class, if true, then MBG creates a class without a setter method, instead of a class like constructorbased-- <property name= "Immutable" value= "false"/> <!--set a root object, if this root object is set, then the generated keyclass or RECORDCLA
                The SS inherits this class, which can be overridden in the Rootclass property of the table note: If you have the same root class attribute in the key class or record class, MBG will not regenerate these properties, including: 1, same property name, same type, same Getter/setter method;--<property Name= "Rootclass" value= "Com._520it.mybatis . Domain. Basedomain "/>

        <!--set whether to call the trim () method on a String type field in the Getter Method--<property name= "Trimstrings" value= "true"/>
 </javaModelGenerator>
(v) <sqlMapGenerator> elementsProperties for defining the SQL Map generator

Targetpackage and Targetproject properties are similar to <javaModelGenerator> elements

Note: If the Mapper.xml file is located in the Web-inf/mapper folder. Targetpackage= "Webcontent.web-inf.mapper" (v) <javaClientGenerator> elements

Used to define the properties of the Java Client Builder. DAO Layer Interface Java class

Type attribute: Select how to generate the Mapper interface (under Mybatis3/mybatis3simple)

1,annotatedmapper: Created in a way that uses the Mapper interface +annotation (SQL generated in annotation) and does not generate the corresponding XML;
2,mixedmapper: With a hybrid configuration, the Mapper interface is generated and appropriate annotation is added, but XML is generated in XML;
3,xmlmapper: Generates mapper interface, interface completely dependent on XML; (default)
Note that if the context is mybatis3simple: only Annotatedmapper and Xmlmapper are supported

Targetpackage and Targetproject properties are similar to <javaModelGenerator> elements (vi) <table> elements

Used to select a table for introspection in the database

(1) Name of the table in the TableName database

(2) The name of the domain class generated by domainobjectname, if not set, use the table name directly as the domain class name

(3) Other properties

<!--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"/>
(4) < columnoverride> elements as child elements of table

To modify the properties of a column in a table, MBG uses the modified columns to generate the properties of the domain

<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 used to specify the attribute type of the generated domain, using the fully qualified name of the type Java.lang.Object
	< Property Name= "Javatype" value= ""/>

	-<!--jdbctype to specify the JDBC type of the column VARCHAR
	<property name= " Jdbctype "value=" "/>
	-

	<!--Typehandler is used to specify the Typehandler that the column uses to, and if you want to specify, configure the full-qualified name of the type processor
	, In MyBatis, typehandler that are not generated into Mybatis-config.xml
	will only generate similar: where id = #{id,jdbctype=bigint,typehandler=com._ 520it.mybatis.mytypehandler} parameter Description
	<property name= "Jdbctype" value= ""/>-

	<!-- Refer to the Delimitallcolumns configuration of the table element, which defaults to false
	<property name= "delimitedcolumnname" value= ""/>-
	

(5) The <ignoreColumn> element is used to tell the MyBatis generator (MBG) to ignore columns in the Introspection table

Delimitedcolumnname If True, MBG performs an exact case-sensitive match when matching the returned columns in the database. If False (the default), the name is considered to be case insensitive.

<ignorecolumn column= "DeptID" delimitedcolumnname= ""/>
(6) <generatedKey> to generate a method for generating a primary key 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: The equivalent of Selectkey is: SELECT scope_identity ()
SYBASE: SQL equivalent to Selectkey: SELECT @ @IDENTITY
JDBC: equivalent to adding usegeneratedkeys= "true" and Keyproperty properties on the resulting insert element
<generatedkey column= "" sqlstatement= ""/>
(7) <columnRenamingRule> element This element renames the column name before calculating the object property name based on the column name in the table, and is well suited for use in tables where columns have common prefix strings 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 and so on, but first replaced with Id,name,email, and then into attributes: Id,name,email;
Note that MBG uses JAVA.UTIL.REGEX.MATCHER.REPLACEALL to replace SearchString and replacestring,
If the columnoverride element is used, the property is invalid;
<columnrenamingrule searchstring= "" replacestring= ""/>
(vii) <commentGenerator> elements
<commentGenerator>
	<!--whether to remove auto-generated annotations true: Yes: false: No---
	<property
		name= " Suppressallcomments "
		value=" true "/>
</commentGenerator>
(1) suppressallcomments is used to specify whether MBG will include any comments in the generated code default false (2) suppressdate is used to specify whether MBG contains the build timestamp in the generated comments. The default False (3) addremarkcomments is used to specify whether MBG contains table and column comments in the generated comments in the database table by default false

(4) Date format string used by DateFormat date to write generated comments

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.