Mybatis Generator Most complete configuration detailedWord Count 3639 read 7849 comments 3 likes 11
Paste_image.png
The students are blessed, spent some time, re-organized a most complete MyBatis Generator (abbreviated MBG) The most complete configuration file, with detailed, no longer to see the user guide en;
<?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 whole 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=" "/>-<!--the dependent package Location property that needs to be loaded when the MBG is working indicates the full path of the load Jar/zip package <classpathentry Locatio
n= "/program files/ibm/sqllib/java/db2java.zip"/>-<!--context: Creating an Environment ID for a set of objects: required, context ID, for prompting when generating an error 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, to generate an object separately, and other simple properties in an object (record Class) Targetruntime:1,mybatis3: Default value, raw Content based on mybatis3.x or above, including xxxbysample; 2,mybatis3simple: Similar to MyBatis3, except that xxxbysample is not generated; Introspectedcolumnimpl: Class fully qualified name , for extended MBG--<context id= "MySQL" defaultmodeltype= "Hierarchical" targetruntime= "Mybatis3simple" > <!--Auto
Identifies the database keyword, false by default, if set to true, based on the list of keywords defined in sqlreservedwords; typically retains the default value, encounters the database keyword (Java keyword), uses columnoverride overlay- <property name= "Autodelimitkeywords" value= "false"/> <!--generated Java file encoding--<property name= "JAVAF Ileencoding "value=" UTF-8 "/> <!--formatted Java code--<property name=" Javaformatter "value=" Org.mybatis.gene Rator.api.dom.DefaultJavaFormatter "/> <!--formatted XML code--<property name=" Xmlformatter "value=" Org.mybat Is.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;--&Gt <property name= "Beginningdelimiter" value= "'"/> <property name= "endingdelimiter" value= "'"/> <!-- Must have, use this configuration to link the database @TODO: can be extended--<jdbcconnection driverclass= "Com.mysql.jdbc.Driver" Connectionur L= "Jdbc:mysql:///pss" userid= "root" password= "admin" > <!--this allows you to set the property properties, each of which is set to the driver of the configuration--&
Gt </jdbcConnection> <!--java type processors are used to process types in db into Java, using Javatyperesolverdefaultimpl by default; note that The default is to try using Integer,long,short to correspond to the decimal and numeric data types, and <javatyperesolver type= Org.mybatis.generator.inter
Nal.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 element that must be responsible for: 1,key class (see Context D Efaultmodeltype); 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, specifying a Save In the 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" ta rgetproject= "Src/main/java" > <!--for mybatis3/mybatis3simple automatically creates a constructor method for each generated class that contains all the Fiel D; instead of using setter;-<property name= "constructorbased" value= "false"/> <!--in Targetpac Kage, based on the database schema regenerated into a layer of the 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 non-setter party The class of law, instead of a class like constructorbased-<property name= "immutable" value= "false"/> <!--Set Setting a root object, if you set aThis root object, the generated Keyclass or Recordclass will inherit the class, which can be overridden in the Rootclass property of the table note: If you have the same root class in the key class or the record class Properties, MBG will not regenerate these properties, including: 1, same property name, same type, same Getter/setter method;--<property Name= "ROOTC
Lass "value=" Com._520it.mybatis.domain.basedomain "/> <!--setting whether to call the trim () method on a String type field in the Getter Method--
<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 the Mapper interface), or only the Mapper interface +annotation, so if Javaclientgenera If you configure the Tor configuration to generate XML, this element must be configured Targetpackage/targetproject: Same as Javamodelgenerator-<sqlmapgenerator t Argetpackage= "Com._520it.mybatis.mapper" targetproject= "src/main/resources" > <!--on the basis of Targetpackage, based on 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 Javamodelgenerat Or type: Choose how to generate the Mapper interface (under Mybatis3/mybatis3simple): 1,annotatedmapper: Generated using the Mapper interface +annotation (SQL Generated in annotation), the corresponding XML is not generated; 2,mixedmapper: With a hybrid configuration, mapper interfaces are generated and appropriate annotation are added, but XML is generated in XML; 3,x Mlmapper: The Mapper interface is generated and the interface is entirely XML-aware, if the context is mybatis3simple: only Annotatedmapper and Xmlmapper are supported--<JAVACL Ientgenerator targetpackage= "Com._520it.mybatis.mapper" type= "Annotatedmapper" targetproject= "Src/main/java" > & lt;! --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= "Enablesubpack Ages "value=" true "/> <!--can add a parent interface for all generated interfaces, but MBG is only responsible for the build and is not responsible for checking <property name=" Rootinterface "Valu
E= ""/>-</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, generate a primary key class, 3, except the BLOB and the primary key of the other fields of the class, 4, the class containing the Blob, 5, a user to generate a dynamic query condition class (Selectbyexam PLE, deletebyexample), optional; 6,mapper interface (optional) tableName (necessary): To generate the table name of the object; Note: Case sensitive issues. Under normal circumstances, MBG will automatically identify the case sensitivity of the database identifier, in general, MBG according to the set Schema,catalog or tablename to query the data table, according to the following process: 1, if the schema, If there are spaces in the catalog or tablename, then what format is set, the exact 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 looks up; 3, otherwise, if The identifier for the database is lowercase, then MBG automatically turns the table name to lowercase, and 4, otherwise, uses the specified case format query, and if, when creating the table, use the "" to specify the case of the database object, even if the database identifier is used in uppercase, The table name is also created using the given case, and this time, set delimitidentifiers= "true" to preserve the case format; Optional: 1,schema: Database schema; 2, Catalog: The 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,dom
Ainobjectname: The name of the generated domain class, if not set, directly using the table name as the domain class name, can be set to Somepck.domainname, then will automatically put 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 quotation marks, if a database like MySQL, using the ' (anti-quote, then you need to set the context of the Beginningdelimiter and Endingdelimiter properties) 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"/> <!--default to False if set
Set to True, the table name will not be added to the catalog or schema in the generated SQL, and <property name= "Ignorequalifiersatruntime" value= "false"/>
<!--reference Javamodelgenerator immutable 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, and if Sqlmapgenerator is also configured, only resultmap elements are generated in the mapper XML file-and < ;p roperty name= "Modelonly" value= "false"/> <!--reference Javamodelgenerator Rootclass Properties <property Name= "Rootclass" value= ""/>-<!--reference Javaclientgenerator Rootinterface Properties <prop Erty name= "Rootinterface" value= ""/>-<!--if Runtimecatalog is set, the specified catalog is used in the generated SQL instead of TA The catalog on the BLE element <property name= "Runtimecatalog" value= ""/>-<!--If the Runtimeschem is set A, in the generated SQL, use the specified SchemA, instead of the schema on the table element <property name= "Runtimeschema" value= ""/>-<!--if runtime is set
TableName, in the generated SQL, use the specified TableName instead of the TableName <property name= "Runtimetablename" value= "on the Table element/> -<!--Note that this property is only useful for mybatis3simple, and if the runtime selected is Mybatis3simple, a SelectAll method is generated, if SE is specified Lectallorderbyclause, the specified order condition is added to the SQL, and <property name= "Selectallorderbyclause" value= "AG E desc,username asc "/> <!--If set to true, the generated model class will use the name of column itself without using the hump naming method, such as Born_date, the generated property name is Born_date Instead of borndate---<property name= "Useactualcolumnnames" value= "false"/> <!--Generatedkey for Raw
Genetic a method that is 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: Equivalent toSelectkey's SQL is: 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 select The SQL for key is: 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: equivalent to Selectkey As: Select Scope_identity () SYBASE: SQL equivalent to Selectkey: SELECT @ @IDENTITY JDBC: equivalent to the Add usegeneratedkeys= "True" and Keyproperty properties on the resulting 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 columns have a common prefix string, such as the column name: CUST_ID,CUST_NAME,CUST_EMAIL,CU St_address and so on, then you can set SearchString to "^cust_" and use blank substitution, then the property name in the generated customer object is not custid,custname, but is replaced first To Id,naMe,email, and then into properties: 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= "/>-->
; <!--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 multiple columnoverride in a TABLE element Soha ~--<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
<property name= "Javatype" value= ""/>-<!--jdbctype Specifies the JDBC type for this column <property name= "Jdbctype" value= ""/>-<!--Typehandler is used to specify the Typehandler to which the column is used, as To specify, the fully qualified name of the configuration type processor is noted that in MyBatis, the typehandler generated into mybatis-config.xml will only generate similar: where id = Parameter description of #{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=" de Limitedcolumnname "value=" "/>-</columnOverride> <!--Ignorecolumn set a M GB ignored column, if the column is set, then in the generated domain, there will be no column in the generated SQL: Specify the name of the column to ignore; Delimitedcolumnname: Refer to the Table element's Delimitallcolumns configuration, default to False note that there can be multiple ignorecolumn elements in a TABLE element <ignorecolumn column= "DeptID" Deli Mitedcolumnname= ""/>-</table> </context> </generatorConfiguration>
Okay, that's it. You can view it as a tool document.
Article reprinted from: http://www.jianshu.com/p/e09d2370b796