Mybatis-generator configuration file Detailed

Source: Internet
Author: User

<?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, such as 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 you use the MyBatis-generator-maven-plugin, the properties defined in Pom.xml can be used directly in the Generatorconfig.xml<properties resource= "" url= ""/>-<!--when working in MBG, the dependent package Location property that requires additional load indicates that the jar is loaded/full path of the ZIP package<classpathentry location= "/program files/ibm/sqllib/java/db2java.zip"/>--><!--Context : Generates an environment ID for a set of objects: required, context ID, to prompt defaultmodeltype when generating an error: Specifies the style of the build object1, conditional: similar to hierarchical;2, flat: All content (primary key, BLOB) and so on are all generated in an object;3,hierarchical: Primary key generates a Xxkey object (keyclass), blobs, and so on, generate an object separately, and other simple properties in an object (recordclass) Targetruntime:1, MyBatis3: Default value that generates content based on mybatis3.x or above, including xxxbysample;2, Mybatis3simple: Similar to MYBATIS3, just do not generate xxxbysample; Introspectedcolumnimpl: Class fully qualified name for extending MBG--><context id= "MySQL" defaultmodeltype= "Hierarchical" targetruntime= "Mybatis3simple" > <!--automatic recognition of database keywords, default false, if set to true, according to the list of keywords defined in Sqlreservedwords, general reserved defaults, encountered database keywords (java keyword), using columnoverride overlay --<property name= "Autodelimitkeywords" value= "false"/> <!--generated Java file encoding--<property name= " Javafileencoding "value=" UTF-8 "/> <!--formatted Java code--<property name=" Javaformatter "value=" ORG.MYBATIS.G Enerator.api.dom.DefaultJavaFormatter "/> <!--formatted XML code--<property name=" Xmlformatter "value=" Org.myba Tis.generator.api.dom.DefaultXmlFormatter "/> <!--beginningdelimiter and Endingdelimiter: Indicates the symbol used to tag database object names in the database, For example, Oracle is double quotes, mysql default is ' anti-quote;--<property Name= "Beginningdelimiter" value= ""/> <property name= "Endingde Limiter "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 allows you to set the property properties, each of which is set to driver on the configuration--</jdbcConnection> &lt ;! --Java type processors are used to process types in the DB type to Java, using Javatyperesolverdefaultimpl by default, and note that the default is to attempt to use integer,long,short and so on to correspond to Deci Mal and numeric data types;--<javatyperesolver type= "Org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl" > <!--true: Use BigDecimal to correspond to decimal and numeric data typesfalse: Default, scale>0;length>18: Using BigDecimal; Scale=0;length[10,18]: use long;=0;length[5,9]: use integer; scale=0;length<5: use short;--<property name= "Forcebigdecimals" value= "false"/> </javaTypeResolver> <!--The Java Model Creator is the element that must be responsible for:1,key Class (see Defaultmodeltype in context); 2,java class; 3, the query class Targetpackage: The generated class to put the package, the real package is controlled by the Enablesubpackages property; Targetproject: Target project, specify an existing directory, the generated content will be placed in the specified directory, if the directory Does not exist, MBG does not automatically build directories--<javamodelgenerator targetpackage= "Com._520it.mybatis.domain" targetproject= "Src/main/java" > <!- - formybatis3/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"/> <!--in targetpackage based on the database schema regenerated into a layer p Ackage, the resulting class is placed under this package and defaults to false--<property name= "Enablesubpackages" value= "true"/> <!-- forMYBATIS3/Mybatis3simple whether to create an immutable class, if true, then MBG will create a class without a setter method instead of a class like constructorbased. /c1>--<property name= "immutable" value= "false"/> <!--sets a root object, and if the root object is set, the generated Keyclass or recordclass inherit the class, which can be overridden in the Rootclass property of the table note: If the key class Or if the record class has the same attributes as the root 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"/> <!--settings in Getter method    , the trim () method is called on the String Type field--<property name= "Trimstrings" value= "true"/> </javaModelGenerator> <!--generate an XML file generator for SQL map, note that after Mybatis3, we can use the Mapper.xml file+Mapper Interface (or not mapper interface), or use only Mapper interface+Annotation, so if the Javaclientgenerator configuration is configured to generate XML, this element must be configured Targetpackage/targetproject: With 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, and the default is false----<property name= "Enablesubpac Kages "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 as Javamodelgenerator type: Choose how to Generate Mapper interface (in MyBatis3/mybatis3simple below):1,annotatedmapper: will be generated using Mapper interface +annotation is created (SQL generated in annotation) and does not generate the corresponding XML;2, Mixedmapper: Using a hybrid configuration, the Mapper interface is generated and appropriate annotation is added, but XML is generated in XML;3, Xmlmapper: The Mapper interface is generated and the interface is entirely XML-aware, if the context is mybatis3simple: only Annotatedmapper and Xmlmapper are supported--<javaclientgenerator targetpackage= "Com._520it.mybatis.mapper" type= "annotatedmapper" targetProject= "src /main/java "> <!--on the basis of targetpackage, according to the database schema regenerated into a layer of package, the resulting class is placed under this package, the default is false--and <p Roperty name= "Enablesubpackages" value= "true"/> <!--you can add a parent interface for all the generated interfaces, but the MBG is only responsible for the build and is not responsible for checking<property name= "Rootinterface" value= ""/>-</javaClientGenerator> <!--Select a table to generate the related file, you can have one or more table, you must have table element selected table will generate the file:1, the SQL map file2, a primary key class is generated;3, except for the Blob and the class of the other fields of the primary key;4A class that contains a blob;5, a user-generated condition class for dynamic queries (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 precise use of the specified case format to query;2, otherwise, if the database identifier is capitalized, then MBG automatically turns the table name into uppercase and then finds it;3, otherwise, if the database identifier is lowercase, then MBG automatically turns the table name into lowercase and then looks for it;4Otherwise, use the specified case format query, and, if the table is created, use the""The database object is specified in case, even if the database identifier is capitalized, the table name is also created using the given case, and this time, please set the delimitidentifiers= "true"you can keep the case format, optionally:1, Schema: The schema of the database;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_actualcolumnname4, 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, specifying 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 ' (back quotes, 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 copy of the default properties of elements such as Javamodelgenerator,context;--<table tablename= "userinfo" > <!--reference Javamodelgenerator constructorbased Properties--<p Roperty name= "constructorbased" value= "false"/> <!--default to False, 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 Immut Able Properties-<property name= "immutable" value= "false"/> <!--Specifies whether to generate only the domain class, and if set to True, only the domain class is generated,        If Sqlmapgenerator is also configured, in the mapper XML file, only Resultmap elements are generated--<property name= "Modelonly" value= "false"/> <!--refer to the Rootclass property of Javamodelgenerator<property name= "Rootclass" value= ""/>-<!--refer to the Rootinterface property of 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, the specified tablename is used in the generated SQL instead of the tablename on the table element<property name= "Runtimetablename" value= ""/>-<!--Note that this property is only useful for mybatis3simple, and if the runtime chosen is Mybatis3simple, a SelectAll method is generated, and if Selectallorderbyclause is specified, the The specified order condition is added to the SQL;--<property name= "Selectallorderbyclause" value= "Age desc,username ASC"/> <!--If set to true, the generated MO The Del class will use the name of column itself without using the hump naming method, such as born_date, to generate a property named Born_date instead of Borndate--and <property name= " Useactualcolumnnames "value=" false "/> <!--Generatedkey is used to generate a method for generating a primary key, and if the element is set, MBG will generate theGenerate a correct <selectKey> in the <insert> elementelement, which is optional column name of the primary key; SQLStatement: The Selectkey statement to be generated has the following options: Cloudscape: Equivalent to SELECTK                EY's SQL is: 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: equivalent to Selectke The SQL for Y is: Call IDENTITY () Informix: SQL equivalent to Selectkey: Select Dbinfo (' Sqlca.sqlerrd1 ') from Systables where tabid=1MYSQL: SQL equivalent to Selectkey: SELECT last_insert_id () SQL Server: Selectkey equivalent to: Sele CT scope_identity () SYBASE: SQL equivalent to Selectkey: SELECT @ @IDENTITY JDBC: Equivalent to the generated Inser Add Usegeneratedkeys on t element= "true"and Keyproperty Properties<generatedkey column= "" sqlstatement= ""/>-<!--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 a common prefix string, such as the column name: Cust_id,cust_name,cust_email,cust_ad Dress and so on, then you can set SearchString to"^cust_", and replace with whitespace, the property name in the generated customer object is not custid,custname, etc., but is replaced with Id,name,email first, then the property: Id,name,email; note , MBG uses JAVA.UTIL.REGEX.MATCHER.REPLACEALL to replace SearchString and replacestring, which is invalid if the columnoverride element is used; 
    <columnrenamingrule searchstring= "" replacestring= ""/>-<!--to modify the properties of a column in a table, MBG uses the modified column to generate the domain's properties; columns: The name of the list to be reset; Note that there can be more than one columnoverride element 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= "Property" value= "UserName"/> <!--Javatype used to specify the property type of the generated domain, using the fully qualified name of the type<property name= "Javatype" value= ""/>-<!--Jdbctype used to specify the JDBC type of the column<property name= "Jdbctype" value= ""/>-<!--The Typehandler is used to specify the Typehandler that the column uses, and if you want to specify the fully qualified name of the configuration type processor, note that MyBatis is not generated to MyBatis-in CONFIG. Typehandler only generates a similar: where ID= #{id,jdbctype=bigint,typehandler=parameter description for Com._520it.mybatis.mytypehandler}<property name= "Jdbctype" value= ""/>-<!--refer to the Delimitallcolumns configuration of the table element, default to False<property name= "Delimitedcolumnname" value= ""/>-</columnOverride> <!--Ignorecolumn set a MGB ignored column, if the column is set, in the generated domain, there will be no columns in the generated SQL: Specify the name of the column to ignore; DELIMITEDC Olumnname: 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></generato Rconfiguration>

Mybatis-generator configuration file Detailed

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.