From ba705b99ca35f96a2a52b5c03490ee8259fda510 Mon Sep 17 00:00:00 2001 From: Xavi Lee Date: Mon, 6 Jun 2022 13:01:03 +0800 Subject: [PATCH] translate the doc for zh-CN --- core/mybatis-generator-core/pom.xml | 1 + .../src/site/site_zh.xml | 95 ++ .../src/site/zh/resources/css/site.css | 17 + .../src/site/zh/resources/mbgstyle.css | 18 + .../src/site/zh/xhtml/afterRunning.xhtml | 74 ++ .../configreference/classPathEntry.xhtml | 73 ++ .../configreference/columnOverride.xhtml | 163 ++++ .../configreference/columnRenamingRule.xhtml | 124 +++ .../configreference/commentGenerator.xhtml | 193 ++++ .../configreference/connectionFactory.xhtml | 109 +++ .../zh/xhtml/configreference/context.xhtml | 281 ++++++ .../domainObjectRenamingRule.xhtml | 118 +++ .../zh/xhtml/configreference/except.xhtml | 70 ++ .../xhtml/configreference/generatedKey.xhtml | 132 +++ .../generatorConfiguration.xhtml | 51 + .../xhtml/configreference/ignoreColumn.xhtml | 64 ++ .../ignoreColumnsByRegex.xhtml | 69 ++ .../configreference/javaClientGenerator.xhtml | 190 ++++ .../configreference/javaModelGenerator.xhtml | 182 ++++ .../configreference/javaTypeResolver.xhtml | 161 ++++ .../configreference/jdbcConnection.xhtml | 89 ++ .../zh/xhtml/configreference/plugin.xhtml | 69 ++ .../zh/xhtml/configreference/properties.xhtml | 71 ++ .../zh/xhtml/configreference/property.xhtml | 57 ++ .../configreference/sqlMapGenerator.xhtml | 115 +++ .../site/zh/xhtml/configreference/table.xhtml | 526 ++++++++++ .../zh/xhtml/configreference/xmlconfig.xhtml | 149 +++ .../xhtml/generatedobjects/dynamicSql.xhtml | 234 +++++ .../generatedobjects/dynamicSqlKotlin.xhtml | 238 +++++ .../generatedobjects/exampleClassUsage.xhtml | 147 +++ .../extendingExampleClass.xhtml | 217 +++++ .../xhtml/generatedobjects/javaclient.xhtml | 93 ++ .../zh/xhtml/generatedobjects/javamodel.xhtml | 141 +++ .../zh/xhtml/generatedobjects/legacy.xhtml | 44 + .../zh/xhtml/generatedobjects/results.xhtml | 54 ++ .../zh/xhtml/generatedobjects/sqlmap.xhtml | 232 +++++ .../src/site/zh/xhtml/index.xhtml | 151 +++ .../src/site/zh/xhtml/license.xhtml | 48 + .../site/zh/xhtml/migratingFromAbator.xhtml | 71 ++ .../site/zh/xhtml/migratingFromIbator.xhtml | 52 + .../src/site/zh/xhtml/philosophy.xhtml | 67 ++ .../src/site/zh/xhtml/quickstart.xhtml | 194 ++++ .../site/zh/xhtml/reference/building.xhtml | 60 ++ .../site/zh/xhtml/reference/extending.xhtml | 162 ++++ .../src/site/zh/xhtml/reference/intro.xhtml | 38 + .../src/site/zh/xhtml/reference/logging.xhtml | 154 +++ .../site/zh/xhtml/reference/pluggingIn.xhtml | 130 +++ .../src/site/zh/xhtml/reference/plugins.xhtml | 226 +++++ .../src/site/zh/xhtml/running/running.xhtml | 60 ++ .../zh/xhtml/running/runningFromCmdLine.xhtml | 95 ++ .../zh/xhtml/running/runningWithAnt.xhtml | 116 +++ .../zh/xhtml/running/runningWithEclipse.xhtml | 74 ++ .../zh/xhtml/running/runningWithJava.xhtml | 80 ++ .../zh/xhtml/running/runningWithMaven.xhtml | 341 +++++++ .../src/site/zh/xhtml/usage/db2.xhtml | 40 + .../src/site/zh/xhtml/usage/intro.xhtml | 40 + .../src/site/zh/xhtml/usage/mysql.xhtml | 60 ++ .../src/site/zh/xhtml/usage/oracle.xhtml | 47 + .../src/site/zh/xhtml/usage/postgresql.xhtml | 57 ++ .../src/site/zh/xhtml/whatsNew.xhtml | 910 ++++++++++++++++++ 60 files changed, 7934 insertions(+) create mode 100644 core/mybatis-generator-core/src/site/site_zh.xml create mode 100644 core/mybatis-generator-core/src/site/zh/resources/css/site.css create mode 100644 core/mybatis-generator-core/src/site/zh/resources/mbgstyle.css create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/afterRunning.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/classPathEntry.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/columnOverride.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/columnRenamingRule.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/commentGenerator.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/connectionFactory.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/context.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/domainObjectRenamingRule.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/except.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/generatedKey.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/generatorConfiguration.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/ignoreColumn.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/ignoreColumnsByRegex.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/javaClientGenerator.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/javaModelGenerator.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/javaTypeResolver.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/jdbcConnection.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/plugin.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/properties.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/property.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/sqlMapGenerator.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/table.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/configreference/xmlconfig.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/dynamicSql.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/dynamicSqlKotlin.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/exampleClassUsage.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/extendingExampleClass.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/javaclient.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/javamodel.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/legacy.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/results.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/sqlmap.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/index.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/license.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/migratingFromAbator.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/migratingFromIbator.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/philosophy.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/quickstart.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/reference/building.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/reference/extending.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/reference/intro.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/reference/logging.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/reference/pluggingIn.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/reference/plugins.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/running/running.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/running/runningFromCmdLine.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithAnt.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithEclipse.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithJava.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithMaven.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/usage/db2.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/usage/intro.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/usage/mysql.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/usage/oracle.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/usage/postgresql.xhtml create mode 100644 core/mybatis-generator-core/src/site/zh/xhtml/whatsNew.xhtml diff --git a/core/mybatis-generator-core/pom.xml b/core/mybatis-generator-core/pom.xml index 6a6fa5f1b3..20bd3ec4e5 100644 --- a/core/mybatis-generator-core/pom.xml +++ b/core/mybatis-generator-core/pom.xml @@ -44,6 +44,7 @@ false false + en,zh_CN diff --git a/core/mybatis-generator-core/src/site/site_zh.xml b/core/mybatis-generator-core/src/site/site_zh.xml new file mode 100644 index 0000000000..9f41ebc846 --- /dev/null +++ b/core/mybatis-generator-core/src/site/site_zh.xml @@ -0,0 +1,95 @@ + + + + + + MyBatis 生成器 + index.html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/mybatis-generator-core/src/site/zh/resources/css/site.css b/core/mybatis-generator-core/src/site/zh/resources/css/site.css new file mode 100644 index 0000000000..31f7a6e38b --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/resources/css/site.css @@ -0,0 +1,17 @@ +/** + * Copyright 2006-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#leftColumn {width: 20%} +#bodyColumn {width:75%} diff --git a/core/mybatis-generator-core/src/site/zh/resources/mbgstyle.css b/core/mybatis-generator-core/src/site/zh/resources/mbgstyle.css new file mode 100644 index 0000000000..7771936029 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/resources/mbgstyle.css @@ -0,0 +1,18 @@ +/** + * Copyright 2006-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* custom stylesheet - used to override any maven style, and as a placeholder + * for the eclipse help stylesheet + */ diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/afterRunning.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/afterRunning.xhtml new file mode 100644 index 0000000000..eb3a12512e --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/afterRunning.xhtml @@ -0,0 +1,74 @@ + + + + + + 运行 MyBatis Generator 之后 + + + +

运行 MyBatis Generator 之后

+

运行 MyBatis Generator 之后,你需要创建或修改其他 MyBatis 配置文件。主要任务是创建或修改 MapperConfig.xml 文件。

+ +

更新 MapperConfig.xml 文件(MyBatis 3.x)

+

MyBatis 3.x 使用XML文件,通常命名为 MapperConfig.xml, +来指定将在 MyBatis 会话中使用的数据库连接、事务管理方案和 XML 映射器文件的信息。MBG 无法为你创建此文件,因为它对你的执行环境一无所知。但是,此文件中的某些配置直接与 MBG 生成的项目相关。有关不同配置选项的详细信息,请参阅 MyBatis 的相关文档。

+ +

MBG 配置文件中的具体需求如下:

+
    +
  • MBG 必须列出生成的 XML 映射器文件
  • +
+ +

例如,假设MBG生成了一个名为 +MyTableMapper.xml 的文件,并且文件已放置在 +test.xml 的包中,MapperConfig.xml 文件应具有以下条目:

+
+  <?xml version="1.0" encoding="UTF-8"?>
+  <!DOCTYPE configuration
+    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
+    "http://mybatis.org/dtd/mybatis-3-config.dtd">
+
+  <configuration>
+    <!-- Setup the transaction manager and data source that are
+         appropriate for your environment
+    -->
+    <environments default"...">
+      <environment id"...">
+        <transactionManager type="...">
+        </transactionManager>
+        <dataSource type="...">
+        </dataSource>
+      </environment>
+    </environments>
+
+    <mappers>
+      <!-- XML mapper files should be listed here -->
+      <mapper resource="test/xml/MyTable_SqlMap.xml" />
+    </mappers>
+
+  </configuration>
+
+ +

如果有多个 XML 映射器文件(这很常见),则文件可以在 <mappers> 里面使用 <mapper> 以任意顺序列出。

+ +

如果你使用基于 Java 的配置或 Spring,则需要以合适方式注册映射器。

+ + + \ No newline at end of file diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/classPathEntry.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/classPathEntry.xhtml new file mode 100644 index 0000000000..218af08c66 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/classPathEntry.xhtml @@ -0,0 +1,73 @@ + + + + + + The <classPathEntry> Element + + + +

The <classPathEntry> Element

+

The <classPathEntry> element is used to add classpath locations to the +classpath of the MyBatis Generator (MBG) run. The <classPathEntry> element is an option child +element of the <generatorConfiguration> element. +MBG loads classes from these locations in these instances:

+
    +
  • When loading the JDBC driver for database introspection
  • +
  • When loading root classes in the JavaModelGenerator to check for overridden + methods
  • +
+ +

This element is optional and is not required if you setup the classpath externally to MBG +(e.g. with the -cp argument of the java command

+ +

Important Note: these locations are NOT used when loading classes that +extend one of MBG's classes or implement one of MBG's interfaces. In those cases +you must add your external classes to the runtime classpath in the same way you +add MBG to the classpath (e.g. with the -cp argument of the +java command).

+ +

Required Attributes

+ + + + + + + + + +
AttributeDescription
locationThe full path name of a JAR/ZIP file to add to the classpath, or + a directory to add to the classpath.
+ +

Optional Attributes

+

None

+ +

Child Elements

+

None

+ + +

Example

+

This element specifies the location of a DB2 JDBC driver:

+
+<classPathEntry location="/Program Files/IBM/SQLLIB/java/db2java.zip" />
+
+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/columnOverride.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/columnOverride.xhtml new file mode 100644 index 0000000000..c84a35553d --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/columnOverride.xhtml @@ -0,0 +1,163 @@ + + + + + + The <columnOverride> Element + + + +

The <columnOverride> Element

+

MyBatis Generator (MBG) uses the <columnOverride> element to change certain +attributes of an introspected database column from the values that would be calculated by +default. This element is an optional child +element of the <table> element.

+ +

Required Attributes

+ + + + + + + + + +
AttributeDescription
columnThe column name of the introspected.
+ +

Optional Attributes

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeDescription
propertyThe name of a Java property to be used. If not specified, + MBG will generate properties based on the column name. + For example, if a table has a column named "STRT_DTE" then MBG + will generate the property name as either "STRT_DTE" or "strtDte" + based on the value of the "useActualColumnNames" property (see the + description of the <table> element for more information). + This property could be used to rename the column "startDate"
javaTypeThe fully qualified Java Type of the property for this column. This + can be used to override the type calculated by the JavaTypeResolver + if required. For some databases, this is necessary to handle + "odd" database types (e.g. MySql's unsigned bigint type + should be mapped to java.lang.Object).
jdbcTypeThe JDBC Type (INTEGER, DECIMAL, NUMERIC, VARCHAR, etc.) for the column. + This can be used to override the type calculated by the JavaTypeResolver + if required. For some databases this is necessary to handle JDBC driver + quirks (e.g. DB2's LONGVARCHAR type should be mapped to VARCHAR for MyBatis).
typeHandlerA user defined type handler that should be used for this column. + This should be the fully + qualified name of a class that implements MyBatis' + TypeHandler + interface. + If unspecified, or blank, + then MyBatis will use the default type facility for handling types. + Important: MBG does not verify that this type handler exists, + or is valid. MBG simply inserts this value at the appropriate places + in the generated SQL Map configuration file. +
delimitedColumnNameSpecifies whether the column name should be delimited in the generated SQL. + MBG will automatically delimit the column name if the name contains a space, + so this override is only necessary when the column name must be forced to a certain + case, or when the column name is a reserved word in the database. +

When "true", the column attribute for the override + must exactly match the case of the column name returned from the database.

+

The delimiter characters are specified on the + <context> element.

+

The default value is false. However, MBG will automatically + delimit column names that contain a space, so no override is necessary + in that case.

+
isGeneratedAlwaysSpecifies whether the column is a GENERATED ALWAYS column in the database. If the column + is GENERATED ALWAYS then MBG will not reference the column in insert or update + statements. +

The default value is false.

+

Since version 1.3.4

+
+ +

Child Elements

+
    +
  • <property> (0..N) + Note: any properties specified here will be added to the + properties collection of the corresponding IntrospectedColumn. MBG does not currently + respond to any properties. This element is provided so that special values + for each column may be provided to a plugin in the event that a plugin is + coded to generate or modify something unique to a particular column.
  • +
+ +

Supported Properties

+

This table lists the properties of the default SQL Map generators that can be +specified with the <property> child element:

+ + + + + + + + + + + + + +
Property NameProperty Values
forceJavaTypeIntoMapping + When true, this property will add the Java type to the generated mappings. This is normally not necessary. + However some functions will need it such as when you use MyBatis' EnumOrdinalTypeHandler. + +

This property is only recognized, and only needed, by the MyBatis3DynamicSQL and MyBatis3Kotlin runtimes.

+

The default value is false

+

Since version 1.4.1

+
trimStrings + This property is used to select whether MyBatis Generator adds code to trim + the white space from character fields returned from the database. + This can be useful if your database stores data in CHAR fields rather than + VARCHAR fields. When true for a character field/column, MyBatis Generator will + insert code to trim leading and trailing whitespace. + This property value overrides the property if specified at the + <javaModelGenerator> and/or + <table> level. + +

The default value is inherited from the + <javaModelGenerator> and/or + <javaModelGenerator>, otherwise false.

+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/columnRenamingRule.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/columnRenamingRule.xhtml new file mode 100644 index 0000000000..ee2734b806 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/columnRenamingRule.xhtml @@ -0,0 +1,124 @@ + + + + + + The <columnRenamingRule> Element + + + +

The <columnRenamingRule> Element

+

MyBatis Generator (MBG) uses the <columnRenamingRule> element +to rename database columns before calculating the corresponding property +name in an introspected table. This is useful when all columns +in a table have a common prefix that should be removed before +calculating the property name. For example, suppose a table +contains the following columns:

+
    +
  • CUST_BUSINESS_NAME
  • +
  • CUST_STREET_ADDRESS
  • +
  • CUST_CITY
  • +
  • CUST_STATE
  • +
+

It might be annoying to have the generated properties + all containing the CUST prefix. The prefix can be removed by + specifying a renaming rule like this:

+ +

<columnRenamingRule searchString="^CUST_" replaceString="" />

+ +

Note that, internally, MBG uses the + java.util.regex.Matcher.replaceAll method + for this function. See the documentation for that method + and class for examples of the regular expression language used in + Java.

+ +

This element will be ignored for any column where a <columnOverride> element + matches a column - the <columnOverride> + will take precedence over the renaming rule.

+ +

If specified, the renaming rule in this element will rename the column + before the property name is calculated. The calculated property name + may be different depending on the value of the + "useActualColumnNames" property on the corresponding <table> element. + The following table shows the different values that will result if + the column renaming rule shown above is applied to the field set + shown above:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Column NameProperty if useActualColumnNames="true"Property if useActualColumnNames="false"
CUST_BUSINESS_NAMEBUSINESS_NAMEbusinessName
CUST_STREET_ADDRESSSTREET_ADDRESSstreetAddress
CUST_CITYCITYcity
CUST_STATESTATEstate
+ +

This element is an optional child +element of the <table> element.

+ +

Required Attributes

+ + + + + + + + + +
AttributeDescription
searchStringThis is a regular expression that defines the substring to be replaced.
+ +

Optional Attributes

+ + + + + + + + + +
AttributeDescription
replaceStringThis is a string to be substituted for every occurrence of the + search string. If not specified, the empty string is used.
+ +

Child Elements

+

None

+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/commentGenerator.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/commentGenerator.xhtml new file mode 100644 index 0000000000..f5ad3394c6 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/commentGenerator.xhtml @@ -0,0 +1,193 @@ + + + + + + The <commentGenerator> Element + + + +

The <commentGenerator> Element

+

The <commentGenerator> element is used to define properties of the Comment Generator. +The Comment Generator is used to generate comments for the various elements generated by +MyBatis Generator (MBG) (Java fields, Java methods, XML elements, etc.). +The default Comment Generator adds JavaDoc comments to all generated Java elements to enable +the Java merge functionality in the Eclipse plugin. Also, comments are added to each +generated XML element. The purpose of the comments is also to inform users that the +elements are generated and are subject to regeneration (i.e. - they shouldn't be +altered). This element is an optional child element +of the <context> element.

+ +

The default implementation is org.mybatis.generator.internal.DefaultCommentGenerator. +The default implementation is designed for extensibility if you only want to modify +certain behaviors.

+ +

Required Attributes

+

None

+ +

Optional Attributes

+ + + + + + + + + +
AttributeDescription
typeThis may be used to specify the type of the user provided Comment Generator. + The class must implement the interface org.mybatis.generator.api.CommentGenerator + and must have a public default constructor. The attribute also accepts + the special value DEFAULT in which case the default implementation will + be used (this has the same effect as not specifying the type).
+ +

Child Elements

+ + +

Supported Properties

+

This table lists the properties of the default comment generator that can be +specified with the <property> child element:

+ + + + + + + + + + + + + + + + + + + + + + + + + +
Property NameProperty Values
suppressAllComments + This property is used to specify whether MBG will include any comments in the + generated code. + The property supports these values: + + + + + + + + + +
falseThis is the default value +
When the property is false or unspecified, all generated elements + will include comments indicating that the element is a generated element. +
trueWhen the property is true, no comments will be added to any + generated element. +
+

Warning: if you set this value to true, then all code merging will be disabled.

+

If you disable all comments, you might find the UnmergeableXmlMappersPlugin useful. It + will cause the generator to respect the overwrite flag for XML files. +

+
suppressDate + This property is used to specify whether MBG will include the generation + timestamp in the generated comments. + The property supports these values: + + + + + + + + + +
falseThis is the default value +
When the property is false or unspecified, all generated comments + will include the timestamp when the element was generated. +
trueWhen the property is true, no timestamp will be added to the + generated comments. +
+
addRemarkComments + This property is used to specify whether MBG will include table and column + remarks from db table in the generated comments. + The property supports these values: + + + + + + + + + +
falseThis is the default value +
When the property is false or unspecified, all generated comments + will not include table and column remarks from db table + when the element was generated. +
trueWhen the property is true, table and columns remarks from db table + will be added to the generated comments. +
+

Warning: If suppressAllComments option is true, this option will be ignored.

+
dateFormatA date format string to use when writing the date into the generated comment. This string + will be used to construct a java.text.SimpleDateFormat object. Any + valid format string for that object can be specified here. By default, the date string + will be from the toString() method on java.util.Date. +

Since 1.3.4

+

Warning: If the suppressAllComments option is true, this option will be ignored.

+

Warning: If the suppressDate option is true, this option will be ignored.

+
useLegacyGeneratedAnnotation + Specifies whether to use an annotation from the deprecated "javax" namespace. In JDK 9+ it is recommended + to use the "jakarta" namespace instead. The property supports these values: + + + + + + + + + +
falseThis is the default value +
When the property is false or unspecified, generated Java elements + will be annotated with jakarta.annotation.Generated +
trueWhen the property is true, generated Java elements will be annotated with + javax.annotation.Generated +
+
+ +

Example

+

This element specifies that we do not want the timestamp added to any generated comment:

+
+<commentGenerator>
+  <property name="suppressDate" value="true" />
+</commentGenerator>
+
+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/connectionFactory.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/connectionFactory.xhtml new file mode 100644 index 0000000000..e2a0c2868a --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/connectionFactory.xhtml @@ -0,0 +1,109 @@ + + + + + + The <connectionFactory> Element + + + +

The <connectionFactory> Element

+

The <connectionFactory> element is used to specify a connection factory for obtaining +the database connection required to introspect tables. MyBatis Generator uses JDBC's +DatabaseMetaData class to discover the properties of the tables you specify +in the configuration. One <connectionFactory> or <jdbcConnection> element +is required for +each <context> element.

+ +

Required Attributes

+

None

+ +

Optional Attributes

+ + + + + + + + + +
AttributeDescription
typeThis may be used to specify the type of the user provided connection factory. + The class must implement the interface org.mybatis.generator.api.ConnectionFactory + and must have a public default constructor. The attribute also accepts + the special value DEFAULT in which case the default implementation will + be used (this has the same effect as not specifying the type).
+ +

Child Elements

+
    +
  • <property> (0..N) + Note: for the default connection factory, any properties specified beyond what is detailed + below will be added to the properties of the JDBC driver.
  • +
+ +

Supported Properties

+

This table lists the properties of the default connection factory that can be +specified with the <property> child element:

+ + + + + + + + + + + + + + + + + + + + + +
Property NameProperty Values
driverClass + This property is used to specify the fully qualified class name of the JDBC driver. This + property is required for the default connection factory. +
connectionURL + This property is used to specify the JDBC connection URL for the database. This + property is required for the default connection factory. +
userId + This property is used to specify the User ID for the connection. +
password + This property is used to specify the password for the connection. +
+ +

Example

+

This element will connect to an HSQLDB in memory database configured as +aname:

+
+<connectionFactory>
+  <property name="driverClass" value="org.hsqldb.jdbcDriver"/>
+  <property name="connectionURL" value="jdbc:hsqldb:mem:aname"/>
+  <property name="userId" value="sa"/>
+</connectionFactory>
+
+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/context.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/context.xhtml new file mode 100644 index 0000000000..0f28a139de --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/context.xhtml @@ -0,0 +1,281 @@ + + + + + + The <context> Element + + + +

The <context> Element

+

The <context> element is used to specify the environment for +generating a set of objects. Child elements are used to specify the database +to connect to, the type of objects to generate, and the tables to introspect. +Multiple <context> elements can be listed inside an +<generatorConfiguration> +element to allow generating objects from different +databases, or with different generation parameters, in the same run of MyBatis Generator (MBG).

+ +

Required Attributes

+ + + + + + + + + +
AttributeDescription
idA unique identifier for this context. This value will be used in some + error messages.
+ +

Optional Attributes

+ + + + + + + + + + + + + + + + + +
AttributeDescription
defaultModelType + This attribute is ignored if the target runtime is "MyBatis3Simple", "MyBatis3DynamicSql", + or "MyBatis3Kotlin"
+ This attribute is used to set the default for generated model types. + The model type defines how MBG will generate domain classes. With some + model types MBG will generate a single domain class for each table, + with others MBG may generate different classes depending on the structure + of the table. The property supports these values: + + + + + + + + + + + + + +
conditionalThis is the default value +
This model is similar to the hierarchical model except that a separate + class will not be generated if that separate class would only contain + one field. So if a table has only one primary key field, that field + will be merged into the base record class.
flatThis model generates only one domain class for any table. The class + will hold all fields in the table.
hierarchicalThis model will generate a primary key class if the table has + a primary key, another class that holds any BLOB columns in the table, and + another class that holds the remaining fields. There is an appropriate + inheritance relationship between the classes.
+
targetRuntime + This property is used to specify the runtime target for generated code. + The property supports these special values: + + + + + + + + + + + + + + + + + +
MyBatis3DynamicSqlThis is the default value
+ With the value, MBG will generate objects that are compatible + with MyBatis versions 3.4.2 and higher, and Java 8 and higher (e.g. the + Java model and mapper interfaces will use generic types and other Java 8 + features like default methods in interfaces). +

Important: The Java code generated with this target runtime is dependent on the + "MyBatis Dynamic SQL" support library version 1.1.3 or higher.

+

Other important information:

+
    +
  • The model objects are generated in the "FLAT" style regardless of what is specified + for the "defaultModelType". This also means that there are no "with BLOBs" and + "without BLOBs" methods.
  • +
  • The mappers are generated as annotated mappers regardless of what is specified + for the "type" of <javaClientGenerator>.
  • +
  • No XML will be generated. <sqlMapGenerator> is not required and will be ignored if specified.
  • +
  • MyBatis Dynamic SQL supports table aliases in a "per query" manner rather than the "all or nothing" + manner of the other runtimes. For this reason, configured table aliases are ignored.
  • +
+
MyBatis3Kotlin + With the value, MBG will generate Kotlin objects that are compatible + with MyBatis versions 3.4.2 and higher. +

Important: The Kotlin code generated with this target runtime is dependent on the + "MyBatis Dynamic SQL" support library version 1.1.4 or higher.

+

Other important information:

+
    +
  • The model objects are generated in the "FLAT" style regardless of what is specified + for the "defaultModelType". This also means that there are no "with BLOBs" and + "without BLOBs" methods.
  • +
  • The mappers are generated as annotated mappers regardless of what is specified + for the "type" of <javaClientGenerator>.
  • +
  • No XML will be generated. <sqlMapGenerator> is not required and will be ignored if specified.
  • +
  • MyBatis Dynamic SQL supports table aliases in a "per query" manner rather than the "all or nothing" + manner of the other runtimes. For this reason, configured table aliases are ignored.
  • +
+
MyBatis3With the value, MBG will generate objects that are compatible + with MyBatis versions 3.0 and higher, and JSE 5.0 and higher (e.g. the + Java model and mapper interfaces will use generic types). + The "by example" methods in these generated objects support virtually + unlimited dynamic where clauses. Additionally, the Java objects + generated with these generators support many JSE 5.0 features including + parameterized types and annotations.
MyBatis3Simple + With the value, MBG will generate objects that are compatible + with MyBatis versions 3.0 and higher, and JSE 5.0 and higher (e.g. the + Java model and mapper interfaces will use generic types). + The mappers generated with this target runtime are very basic + CRUD operations only with no "by example" methods and very little + dynamic SQL. The Java objects + generated with these generators support many JSE 5.0 features including + parameterized types and annotations.
+

If you want to create a different code generator in entirety, + then use this value to specify the fully qualified name of a + class that extends org.mybatis.generator.api.IntrospectedTable. + With this, you can create your own code generator and plug + it in to the code generation engine. See the + Extending MyBatis Generator page for more information. +

+
introspectedColumnImplUse this value to specify the fully qualified name of a + class that extends org.mybatis.generator.api.IntrospectedColumn. + This is used if you want to change the behavior of the code generators + when calculating column information. See the + Extending MyBatis Generator page for more information.
+ +

Child Elements

+ + +

Supported Properties

+

This table lists the properties that can be +specified with the <property> child element:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Property NameProperty Values
autoDelimitKeywordsIf true, then MBG will delimit SQL keywords if they are used as + column names in tables. + MBG maintains a list of SQL keywords + for many different databases. However, the list may not be + totally comprehensive. If a particular keyword is not on MBG's + list, you may force the column to be delimited with a + <columnOverride>.

+

See the source code for the class + org.mybatis.generator.internal.db.SqlReservedWords + for a list of keywords recognized by MBG.

+

The default value is false.

beginningDelimiterThe value to use as the beginning identifier delimiter for SQL identifiers that + require delimiters. MBG will automatically delimit SQL identifiers if the + identifier contains a space. MBG will also delimit SQL identifiers if + specifically requested in a <table> or <columnOverride> configuration.

+

The default value is double quotes (").

endingDelimiterThe value to use as the ending identifier delimiter for SQL identifiers that + require delimiters. MBG will automatically delimit SQL identifiers if the + identifier contains a space. MBG will also delimit SQL identifiers if + specifically requested in a <table> or <columnOverride> configuration.

+

The default value is double quotes (").

javaFileEncodingUse this property to specify an encoding to use when working with Java files. + Newly generated Java files will be written to the file system in this encoding, + and existing Java files will be read with this encoding when performing a merge. + If not specified, then the platform default encoding will be used. +

+

See java.nio.charset.Charset for information on valid encodings.

+
javaFormatterUse this property to specify the full class name of a user provided formatter for generated + Java files. The class must implement org.mybatis.generator.api.JavaFormatter + and must have a default (no argument) constructor. Each context holds a single instance + of the Java formatter. The default Java formatter is + org.mybatis.generator.api.dom.DefaultJavaFormatter. +
kotlinFileEncodingUse this property to specify an encoding to use when working with Kotlin files. + Newly generated Kotlin files will be written to the file system in this encoding. + If not specified, then the platform default encoding will be used. +

+

See java.nio.charset.Charset for information on valid encodings.

+
kotlinFormatterUse this property to specify the full class name of a user provided formatter for generated + Kotlin files. The class must implement org.mybatis.generator.api.KotlinFormatter + and must have a default (no argument) constructor. Each context holds a single instance + of the Kotlin formatter. The default Kotlin formatter is + org.mybatis.generator.api.dom.DefaultKotlinFormatter. +
xmlFormatterUse this property to specify the full class name of a user provided formatter for generated + XML files. The class must implement org.mybatis.generator.api.XmlFormatter + and must have a default (no argument) constructor. Each context holds a single instance + of the XML formatter. The default XML formatter is + org.mybatis.generator.api.dom.DefaultXmlFormatter. The default formatter + uses the formatting built into the XML DOM classes. +
+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/domainObjectRenamingRule.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/domainObjectRenamingRule.xhtml new file mode 100644 index 0000000000..29424d8059 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/domainObjectRenamingRule.xhtml @@ -0,0 +1,118 @@ + + + + + + The <domainObjectRenamingRule> Element + + + +

The <domainObjectRenamingRule> Element

+

MyBatis Generator (MBG) uses the <domainObjectRenamingRule> element +to rename database tables before calculating the corresponding domain object +name. This is useful when all tables have a common prefix that should be +removed before calculating the domain object name. For example, suppose some tables +as the following:

+
    +
  • SYS_USER
  • +
  • SYS_ROLE
  • +
  • SYS_FUNCTION
  • +
+

It might be annoying to have the generated domain object name + all containing the SYS prefix. The prefix can be removed by + specifying a renaming rule like this:

+ +

<domainObjectRenamingRule searchString="^Sys" replaceString="" />

+ +

Note that, internally, MBG uses the + java.util.regex.Matcher.replaceAll method + for this function. See the documentation for that method + and class for examples of the regular expression language used in + Java.

+ +

If specified, the renaming rule in this element will rename all the names base on the + domain object name. Suppose a table named SYS_USER :

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ClassBefore using rename ruleAfter using rename rule
Domain ObjectSysUserUser
KeySysUserKeyUserKey
BlobSysUserWithBLOBsUserWithBLOBs
ExampleSysUserExampleUserExample
MapperSysUserMapperUserMapper
+ +

This element is an optional child +element of the <table> element.

+ +

Required Attributes

+ + + + + + + + + +
AttributeDescription
searchStringThis is a regular expression that defines the substring to be replaced.
+ +

Optional Attributes

+ + + + + + + + + +
AttributeDescription
replaceStringThis is a string to be substituted for every occurrence of the + search string. If not specified, the empty string is used.
+ +

Child Elements

+

None

+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/except.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/except.xhtml new file mode 100644 index 0000000000..dcce2c6cb8 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/except.xhtml @@ -0,0 +1,70 @@ + + + + + + The <except> Element + + + +

The <except> Element

+

The <except> element is used to specify an exception to a set of columns +that are ignored by a regular expression in a +<ignoreColumnsByRegex> element. +This allows you to specify a very general +regular expression to ignore a large set of columns, then add columns back into +the set of columns used for code generation.

+

For example, if you specify a regular +expression like ".*" then MBG will ignore every column in a table. +But if you add exceptions, you can add a few columns back. +This element is an optional child +element of the <ignoreColumnsByRegex> element.

+ +

Required Attributes

+ + + + + + + + + +
AttributeDescription
columnThe column name of the exception column.
+ +

Optional Attributes

+ + + + + + + + + +
AttributeDescription
delimitedColumnNameIf true then MBG will perform a case-sensitive exact + match when matching against returned columns from the database. If + false (default) then the name is considered case-insensitive.
+ +

Child Elements

+

None

+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/generatedKey.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/generatedKey.xhtml new file mode 100644 index 0000000000..7085ca6caa --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/generatedKey.xhtml @@ -0,0 +1,132 @@ + + + + + + The <generatedKey> Element + + + +

The <generatedKey> Element

+

The <generatedKey> element is used to specify properties for +auto generated keys (from identity field or sequences). If you specify this +element, MyBatis Generator (MBG) will generate an appropriate <selectKey> element inside the +generated <insert> element in the SQL map. This element is an optional child +element of the <table> element.

+ +

Required Attributes

+ + + + + + + + + + + + + +
AttributeDescription
columnThe column name of the generated column.
sqlStatementThe SQL statement that will return the new value. If this is + an identity column, then you can use one of the predefined + special values, or substitute the proper statement for your database. + The predefined special values are as follows: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CloudscapeThis will translate to: VALUES IDENTITY_VAL_LOCAL()
DB2This will translate to: VALUES IDENTITY_VAL_LOCAL()
DB2_MFThis will translate to:
SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1 +

Use this value for DB2 on zOS (Main Frames) and, in some cases, iSeries (AS/400)

+
DerbyThis will translate to: VALUES IDENTITY_VAL_LOCAL()
HSQLDBThis will translate to: CALL IDENTITY()
InformixThis will translate to: select dbinfo('sqlca.sqlerrd1') from systables where tabid=1
MySqlThis will translate to: SELECT LAST_INSERT_ID()
SqlServerThis will translate to: SELECT SCOPE_IDENTITY()
SYBASEThis will translate to: SELECT @@IDENTITY
JDBCThis will configure MBG to generate code for MyBatis3 support of JDBC + standard generated keys. This is a database independent method of obtaining + the value from identity columns. +
+
+ +

Optional Attributes

+ + + + + + + + + + + + + +
AttributeDescription
identityIf true, then the column is flagged as an identity column and the + generated <selectKey> element will be placed + after the insert (for an identity column). If false, then + the generated <selectKey> will be placed before the insert + (typically for a sequence). +

Important: Even if you specify the type attribute as "post", + you should still specify this value as "true" for identity columns. This will flag + MBG to remove the column from the insert list.

+

The default is false.

typeIf specified, then this value will be added as the type of the generated <selectKey> element. + The value of this property should be either "pre" or "post". +

Important: if a value is specified for this attribute, then the generated + <selectKey> element will always be placed before the insert statement.

+ +

Child Elements

+

None

+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/generatorConfiguration.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/generatorConfiguration.xhtml new file mode 100644 index 0000000000..8480025d63 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/generatorConfiguration.xhtml @@ -0,0 +1,51 @@ + + + + + + The <generatorConfiguration> Element + + + +

The <generatorConfiguration> Element

+

The <generatorConfiguration> element is the root element of a +MyBatis Generator configuration file. The file should contain the following DOCTYPE: +

+
+<!DOCTYPE generatorConfiguration PUBLIC
+  "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
+  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
+
+ +

Required Attributes

+

None

+ +

Optional Attributes

+

None

+ +

Child Elements

+ + + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/ignoreColumn.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/ignoreColumn.xhtml new file mode 100644 index 0000000000..8579be3787 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/ignoreColumn.xhtml @@ -0,0 +1,64 @@ + + + + + + The <ignoreColumn> Element + + + +

The <ignoreColumn> Element

+

The <ignoreColumn> element is used to tell MyBatis Generator (MBG) to ignore a column +in an introspected table. No generated SQL will refer to the column, and no +property will be generated for the column in the model objects. +This element is an optional child +element of the <table> element.

+ +

Required Attributes

+ + + + + + + + + +
AttributeDescription
columnThe column name of the ignored column.
+ +

Optional Attributes

+ + + + + + + + + +
AttributeDescription
delimitedColumnNameIf true then MBG will perform a case-sensitive exact + match when matching against returned columns from the database. If + false (default) then the name is considered case-insensitive.
+ +

Child Elements

+

None

+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/ignoreColumnsByRegex.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/ignoreColumnsByRegex.xhtml new file mode 100644 index 0000000000..b7ca5e28d1 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/ignoreColumnsByRegex.xhtml @@ -0,0 +1,69 @@ + + + + + + The <ignoreColumnsByRegex> Element + + + +

The <ignoreColumnsByRegex> Element

+

The <ignoreColumnsByRegex> element is used to tell MyBatis Generator (MBG) to ignore a +set of columns in an introspected table - the set is determined by matching against a regular +expression specified in this element. No generated SQL will refer to the ignored columns, and no +properties will be generated for the ignored columns in the model objects. +This element is an optional child +element of the <table> element.

+

You can specify exceptions to the pattern through use of an +<except> element.

+

Required Attributes

+ + + + + + + + + +
AttributeDescription
patternThe regular expression used to match column names. The regular expression + engine is the standard java.util.regex.Pattern engine.
+ +

Optional Attributes

+

None

+ +

Child Elements

+ + +

Example

+

This example tells MyBatis to ignore every column in the Foo table that begins with +the characters "col" (case-insensitive) except for "col01" and "col13".

+
+    <table tableName="Foo">
+      <ignoreColumnsByRegex pattern="(?i)col.*">
+        <except column="col01"/>
+        <except column="col13"/>
+      </ignoreColumnsByRegex>
+    </table>
+
+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/javaClientGenerator.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/javaClientGenerator.xhtml new file mode 100644 index 0000000000..2961c56c2c --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/javaClientGenerator.xhtml @@ -0,0 +1,190 @@ + + + + + + The <javaClientGenerator> Element + + + +

The <javaClientGenerator> Element

+

The <javaClientGenerator> element is used to define properties of the Java +client generator. The Java client Generator builds Java interfaces and classes that allow +easy use of the generated Java model and XML map files. For MyBatis, the +generated objects take the form of mapper interfaces. +This element is a optional child element +of the <context> element. If you do not +specify this element, then MyBatis Generator (MBG) will not generate Java client interfaces and classes.

+

Required Attributes

+ + + + + + + + + + + + + + + + + +
AttributeDescription
typeThis attribute is used to select one of the predefined Java Client generators, or + to specify a user provided Java Client generator. + Any user provided generator must extend the class + org.mybatis.generator.codegen.AbstractJavaClientGenerator + class, and must have a public default constructor. +

The attribute accepts the following values for selecting one of the + predefined generators:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
If the <context> targetRuntime is MyBatis3DynamicSql this attribute is optional and ignored.
If the <context> targetRuntime is MyBatis3Kotlin this attribute is optional and ignored.
If the <context> targetRuntime is MyBatis3 the following predefined values can be used:
ANNOTATEDMAPPERThe generated objects will be Java interfaces for the MyBatis 3.x mapper + infrastructure. The interfaces will be based on annotations and MyBatis 3.x SqlProviders. + No XML mapper files will be generated. +

The ANNOTATEDMAPPER requires MyBatis version 3.0.4 or higher.

+
MIXEDMAPPERThe generated objects will be Java interfaces for the MyBatis 3.x mapper + infrastructure. The interfaces will be based on a mix of annotations and XML. + An annotation will be used where a simple annotation will work. This client + will not generate and Sql Provider, so all complex dynamic SQL will be generated + in XML. +

The MIXEDMAPPER requires MyBatis version 3.0.4 or higher.

+
XMLMAPPERThe generated objects will be Java interfaces for the MyBatis 3.x mapper + infrastructure. The interfaces will be dependent on generated XML mapper files.
If the <context> targetRuntime is MyBatis3Simple the following predefined values can be used:
ANNOTATEDMAPPERThe generated objects will be Java interfaces for the MyBatis 3.x mapper + infrastructure. The interfaces will be based on annotations and MyBatis 3.x SqlProviders. + No XML mapper files will be generated. +

The ANNOTATEDMAPPER requires MyBatis version 3.0.4 or higher.

+
XMLMAPPERThe generated objects will be Java interfaces for the MyBatis 3.x mapper + infrastructure. The interfaces will be dependent on generated XML mapper files.
+
targetPackageThis is the package where the generated interfaces and implementation classes + will be placed. In + the default generators, the property "enableSubPackages" + controls how the actual package is calculated. If true, + then the calculated package will be the targetPackage plus + sub packages for the table's catalog and schema if they exist. + If "enableSubPackages" is false (the default) then the calculated package will be + exactly what is specified in the targetPackage attribute. + MBG will create folders as required for the generated + packages.
targetProjectThis is used to specify a target project for the + generated interfaces and classes. When running in the Eclipse + environment, this specifies the project and source folder where + the objects will be saved. + In other environments, this value should be an existing directory + on the local file system. MBG will not create this directory if + it does not exist.
+ +

Child Elements

+ + +

Supported Properties

+

This table lists the properties of the default SQL Map generators that can be +specified with the <property> child element:

+ + + + + + + + + + + + + + + + + +
Property NameProperty Values
dynamicSqlSupportPackageThis property is only applicable to target runtimes MyBatis3DynamicSql or MyBatis3Kotlin. + Use this property to set the package where generated MyBatis Dynamic SQL Support classes will be placed. + The calculated package can be modified by the "enableSubPackages" property in the same way as the + "targetPackage". + If not specified, the package will be the same as "targetPackage" specified above. +

Since version 1.4.1

+
enableSubPackagesThis property is used to select whether MBG will generate different + Java packages for the objects based on the catalog and schema of the + introspected table. +

For example, suppose a table MYTABLE in schema MYSCHMA. + Also suppose that the targetPackage attribute is set to "com.mycompany". + If this property is true, the generated DAO interface and class for the table + will be placed in + the package "com.mycompany.myschema". If the property is false, the generated + SQL Map will be placed in the "com.mycompany" schema.

+

The default value is false.

rootInterfaceThis property is ignored if the target runtime is "MyBatis3Kotlin"
+ This property can be used to specify a super interface for all generated + interface objects. This value may be overridden by specifying + the rootInterface property on a Table configuration. +

Important: MBG does not verify that the interface exists, or is a + valid Java interface.

+

If specified, the value of this property should be a fully qualified + interface name (like com.mycompany.MyRootInterface).

+ +

Example

+

This element specifies that we always want to place generated interfaces and +objects +in the "'test.model" package and that we want to use subpackages based on the +table schema and catalog. It also specifies that we want to generate +mapper interfaces that reference an XML configuration file for MyBatis3.

+
+<javaClientGenerator targetPackage="test.model"
+     targetProject="\MyProject\src" type="XMLMAPPER">
+  <property name="enableSubPackages" value="true" />
+</javaClientGenerator>
+
+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/javaModelGenerator.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/javaModelGenerator.xhtml new file mode 100644 index 0000000000..857b4a2a9c --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/javaModelGenerator.xhtml @@ -0,0 +1,182 @@ + + + + + + The <javaModelGenerator> Element + + + +

The <javaModelGenerator> Element

+

The <javaModelGenerator> element is used to define properties of the Java model +generator. The Java Model Generator builds primary key classes, record classes, and +Query by Example classes that match the introspected table. This element is a required +child element +of the <context> element.

+

Required Attributes

+ + + + + + + + + + + + + +
AttributeDescription
targetPackageThis is the package where the generated classes will be placed. In + the default generator, the property "enableSubPackages" + controls how the actual package is calculated. If true, + then the calculated package will be the targetPackage plus + sub packages for the table's catalog and schema if they exist. + If false (the default) then the calculated package will be + exactly what is specified in the targetPackage attribute. + MyBatis Generator will create folders as required for the generated + packages.
targetProjectThis is used to specify a target project for the + generated objects. When running in the Eclipse + environment, this specifies the project and source folder where + the objects will be saved. + In other environments, this value should be an existing directory + on the local file system. MyBatis Generator will not create this directory if + it does not exist.
+ +

Optional Attributes

+

None

+ +

Child Elements

+ + +

Supported Properties

+

This table lists the properties of the default Java model generators that can be +specified with the <property> child element:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Property NameProperty Values
constructorBased + This property is used to select whether MyBatis Generator will generate a constructor + for the class that accepts a value for each field in the class. Also, the SQL result map + will be built to use the constructor rather than the "setter" for each field. +

This property is ignored (and forced "true") if the "immutable" property + is set "true".

+

This property can be overridden by the corresponding property in a + <table> element.

+

The default value is false.

+

This property is ignored if the target runtime is "MyBatis3Kotlin"

enableSubPackagesThis property is used to select whether MyBatis Generator will generate different + Java packages for the objects based on the catalog and schema of the + introspected table. +

For example, suppose a table MYTABLE in schema MYSCHMA. + Also suppose that the targetPackage attribute is set to "com.mycompany". + If this property is true, the generated objects for the table will be placed in + the package "com.mycompany.myschema". If the property is false, the generated + objects will be placed in the "com.mycompany" schema.

+

The default value is false.

exampleTargetPackage + This property is used to specify a different package for the generated example objects. If not specified, + the example objects will be generated in the same package as other model objects. +

Note: this property is ignored in the MyBatis Dynamic SQL based runtimes.

+
exampleTargetProject + This property is used to specify a different project for the generated example objects. If not specified, + the example objects will be generated in the same project as other model objects. +

Note: this property is ignored in the MyBatis Dynamic SQL based runtimes.

+
immutable + This property is used to select whether MyBatis Generator will generate immutable + model classes - this means that the classes will not have "setter" methods and + the constructor will accept values for each field in the class. +

If true, this forces the model classes to be built with parameterized constructors + regardless of the value of the "constructorBased" property.

+

This property can be overridden by the corresponding property in a + <table> element.

+

The default value is false.

+

This property is ignored if the target runtime is "MyBatis3Kotlin"

rootClassThis property can be used to specify a root class for all generated + Java model objects. MyBatis Generator will specify this value as the super class + of the primary key object, if the table has a primary key, or the + record object otherwise. This value may be overridden by specifying + the rootClass property on a Table configuration. +

Important: If MyBatis Generator is able to load the root class, then it + will not override a property in the root class that exactly matches a + property that would normally be generated. + An exact match of a property is defined as follows

+
    +
  • Property name matches exactly
  • +
  • Property is of the same type
  • +
  • Property has a "getter" method
  • +
  • Property has a "setter" method
  • +
+

If specified, the value of this property should be a fully qualified + class name (like com.mycompany.MyRootClass).

+

This property is ignored if the target runtime is "MyBatis3Kotlin"

trimStrings + This property is used to select whether MyBatis Generator adds code to trim + the white space from character fields returned from the database. + This can be useful if your database stores data in CHAR fields rather than + VARCHAR fields. When true, MyBatis Generator will insert code to trim character fields. + Can be overridden with the trimStrings property in a + <table> or + <columnOverride> element. +

The default value is false.

+

This property is ignored if the target runtime is "MyBatis3Kotlin"

+ +

Example

+

This element specifies that we always want to place generated classes +in the "'test.model" package and that we want to use subpackages based on the +table schema and catalog. We also want String columns trimmed.

+
+<javaModelGenerator targetPackage="test.model"
+     targetProject="\MyProject\src">
+  <property name="enableSubPackages" value="true" />
+  <property name="trimStrings" value="true" />
+</javaModelGenerator>
+
+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/javaTypeResolver.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/javaTypeResolver.xhtml new file mode 100644 index 0000000000..50e4e16f0b --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/javaTypeResolver.xhtml @@ -0,0 +1,161 @@ + + + + + + The <javaTypeResolver> Element + + + +

The <javaTypeResolver> Element

+

The <javaTypeResolver> element is used to define properties of the Java Type Resolver. +The Java Type Resolver is used to calculate Java types from database column information. +The default Java Type Resolver attempts to make JDBC DECIMAL and NUMERIC types easier +to use by substituting Integral types if possible (Long, Integer, Short, etc.) +If this behavior is undesirable, set the property "forceBigDecimals" to "true". +You can also substitute your own implementation if you want different +behavior than the default. This element is an optional child element +of the <context> element.

+ +

Note: if you use the MyBatis3Kotlin runtime, then the generator will automatically convert Java types to their +appropriate Kotlin equivalents when applicable.

+ +

Required Attributes

+

None

+ +

Optional Attributes

+ + + + + + + + + +
AttributeDescription
typeThis can be used to specify a user provided Java Type Resolver. + The class must implement the interface + org.mybatis.generator.api.JavaTypeResolver, + and must have a public default constructor. The attribute also accepts + the special value DEFAULT in which case the default implementation will + be used (this has the same effect as not specifying the type).
+ +

Child Elements

+ + +

Supported Properties

+

This table lists the properties of the default Java type resolver that can be +specified with the <property> child element:

+ + + + + + + + + + + + + +
Property NameProperty Values
forceBigDecimals + This property is used to specify whether MyBatis Generator should force the use + of java.math.BigDecimal for DECIMAL and NUMERIC fields, + rather than substituting integral types when possible. + The property supports these values: + + + + + + + + + +
falseThis is the default value +
When the property is false or unspecified, the default Java + type resolver will attempt to make JDBC DECIMAL and NUMERIC types + easier to work with by substituting Integral types if possible. The + substitution rules are as follows: +
    +
  • If the scale is greater then zero, or the length is greater + than 18, then the java.math.BigDecimal type will be used
  • +
  • If the scale is zero, and the length is 10 through 18, then the Java + type resolver will substitute a java.lang.Long.
  • +
  • If the scale is zero, and the length is 5 through 9, then the Java + type resolver will substitute a java.lang.Integer.
  • +
  • If the scale is zero, and the length is less than 5, then the Java + type resolver will substitute a java.lang.Short.
  • +
+
trueWhen the property is true, the Java type resolver will always use + java.math.BigDecimal if the database column is of type DECIMAL or NUMERIC.
+
useJSR310Types + This property is used to specify whether MyBatis Generator should force the use + of JSR-310 data types for DATE, TIME, and TIMESTAMP fields, rather than using java.util.Date. + If true, the types will be resolved as follows: + + + + + + + + + + + + + + + + + +
JDBC TypeResolved Java Type
DATEjava.time.LocalDate
TIMEjava.time.LocalTime
TIMESTAMPjava.time.LocalDateTime
+

Note: the type resolver will always resolve the following JSR-310 types regardless of the value of this property:

+ + + + + + + + + + + + + +
JDBC TypeResolved Java Type
TIME_WITH_TIMEZONEjava.time.OffsetTime
TIMESTAMP_WITH_TIMEZONEjava.time.OffsetDateTime
+
+ +

Example

+

This element specifies that we always want to use the java.math.BigDecimal +type for DECIMAL and NUMERIC columns:

+
+<javaTypeResolver>
+  <property name="forceBigDecimals" value="true" />
+</javaTypeResolver>
+
+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/jdbcConnection.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/jdbcConnection.xhtml new file mode 100644 index 0000000000..c025dfb2f0 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/jdbcConnection.xhtml @@ -0,0 +1,89 @@ + + + + + + The <jdbcConnection> Element + + + +

The <jdbcConnection> Element

+

The <jdbcConnection> element is used to specify the properties of +the database connection required to introspect tables. MyBatis Generator uses JDBC's +DatabaseMetaData class to discover the properties of the tables you specify +in the configuration. One <connectionFactory> or <jdbcConnection> element +is required for +each <context> element.

+ +

Required Attributes

+ + + + + + + + + + + + + +
AttributeDescription
driverClassThe fully qualified class name for the JDBC driver used to access the + database. +
connectionURLThe JDBC connection URL used to access the database.
+ +

Optional Attributes

+ + + + + + + + + + + + + +
AttributeDescription
userIdThe user ID used to connect to the database.
passwordThe password used to connect to the database.
+ +

Child Elements

+
    +
  • <property> (0..N) + Note: any properties specified here will be added to the + properties of the JDBC driver.
  • +
+ +

Example

+

This element will connect to a DB2 database configured as +MBGTEST in the DB2 client configuration utility, using +the default install location for the JDBC driver:

+
+<jdbcConnection driverClass="COM.ibm.db2.jdbc.app.DB2Driver"
+    connectionURL="jdbc:db2:MBGTEST"
+    userId="db2admin"
+    password="db2admin">
+</jdbcConnection>
+
+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/plugin.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/plugin.xhtml new file mode 100644 index 0000000000..b684596d14 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/plugin.xhtml @@ -0,0 +1,69 @@ + + + + + + The <plugin> Element + + + +

The <plugin> Element

+

The <plugin> element is used to define a plugin. Plugins can be used +to extend or modify the code generated by MyBatis Generator (MBG). This element is a child element of the +<context> element. Any number of +plugins may be specified in a context. The plugins will be called in +the order that are listed in the configuration.

+ +

For more information about implementing plugins, see the +Implementing Plugins reference +page.

+ +

For more information about plugins supplied with MyBatis Generator, see the +Supplied Plugins reference +page.

+ +

Required Attributes

+ + + + + + + + + +
AttributeDescription
typeThe fully qualified name of the class that implements the plugin. + The class must implement the interface + org.mybatis.generator.api.Plugin, + and must have a public default constructor. Note that it is far + easier to extend the adapter class + org.mybatis.generator.api.PluginAdapter + than to implement the entire interface.
+ +

Optional Attributes

+

None

+ +

Child Elements

+ + + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/properties.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/properties.xhtml new file mode 100644 index 0000000000..cfdcc77ace --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/properties.xhtml @@ -0,0 +1,71 @@ + + + + + + The <properties> Element + + + +

The <properties> Element

+

The <properties> element is used to specify an external properties file +for use in the parsing of the configuration. Any attribute in the +configuration will accept a property in the form ${property}. +The specified properties file will be searched for a matching value and the +matching value will be substituted. The properties file is of the normal +format for a Java properties file.

+

If there are name collisions between a property specified here and +a system property, the system property will win.

+ +

The <properties> element is a child element of the +<generatorConfiguration> +element.

+ + +

Required Attributes

+

One, and only one, of the following attributes is required.

+ + + + + + + + + + + + + +
AttributeDescription
resourceThe qualified name of the property file. When specifying the resource, the + classpath will be searched for the properties file. So a file specified as + com/myproject/generatorConfig.properties must exist in the + com.myproject package.
urlA URL value to use for the property file. This can be used to specify a property + file in a specific place on the file system when used in a form like + file:///C:/myfolder/generatorConfig.properties.
+ +

Optional Attributes

+

None

+ +

Child Elements

+

None

+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/property.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/property.xhtml new file mode 100644 index 0000000000..97d52e49ed --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/property.xhtml @@ -0,0 +1,57 @@ + + + + + + The <property> Element + + + +

The <property> Element

+

The <property> element is used to specify properties for many of the +other elements. The documentation page for each element that supports the +property element lists the different values that are valid. This element +can also be used to pass properties to any custom code generators that +you implement.

+ +

Required Attributes

+ + + + + + + + + + + + + +
AttributeDescription
nameThe name of the property (case sensitive).
valueThe value of the property (typically case insensitive).
+ +

Optional Attributes

+

None

+ +

Child Elements

+

None

+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/sqlMapGenerator.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/sqlMapGenerator.xhtml new file mode 100644 index 0000000000..918ee30ae9 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/sqlMapGenerator.xhtml @@ -0,0 +1,115 @@ + + + + + + The <sqlMapGenerator> Element + + + +

The <sqlMapGenerator> Element

+

The <sqlMapGenerator> element is used to define properties of the SQL map +generator. The SQL Map Generator builds a MyBatis formatted SQL map XML file +for each introspected table.

+

This element is a required child element +of the <context> element only if your chosen +javaClientGenerator requires XML. The runtimes based on MyBatis Dynamic SQL do not generate XML and will +ignore this element if it is specified.

+

If you do not specify a javaClientGenerator, then +the following rules apply:

+
    +
  • If you specify an sqlMapGenerator, then MBG will generate SQL map XML + files and model classes only.
  • +
  • If you do not specify an sqlMapGenerator, then MBG will generate + model classes only.
  • +
+

Required Attributes

+ + + + + + + + + + + + + +
AttributeDescription
targetPackageThis is the package where the generated SQL Maps will be placed. In + the default generators, the property "enableSubPackages" + controls how the actual package is calculated. If true, + then the calculated package will be the targetPackage plus + sub packages for the table's catalog and schema if they exist. + If false (the default) then the calculated package will be + exactly what is specified in the targetPackage attribute. + MyBatis Generator (MBG) will create folders as required for the generated + packages.
targetProjectThis is used to specify a target project for the + generated SQL maps. When running in the Eclipse + environment, this specifies the project and source folder where + the objects will be saved. + In other environments, this value should be an existing directory + on the local file system. MBG will not create this directory if + it does not exist.
+ +

Optional Attributes

+

None

+ +

Child Elements

+ + +

Supported Properties

+

This table lists the properties of the default SQL Map generators that can be +specified with the <property> child element:

+ + + + + + + + + +
Property NameProperty Values
enableSubPackagesThis property is used to select whether MBG will generate different + Java packages for the objects based on the catalog and schema of the + introspected table. +

For example, suppose a table MYTABLE in schema MYSCHMA. + Also suppose that the targetPackage attribute is set to "com.mycompany". + If this property is true, the generated SQL Map for the table will be placed in + the package "com.mycompany.myschema". If the property is false, the generated + SQL Map will be placed in the "com.mycompany" schema.

+

The default value is false.

+ +

Example

+

This element specifies that we always want to place generated SQL Maps +in the "'test.model" package and that we want to use subpackages based on the +table schema and catalog.

+
+<sqlMapGenerator targetPackage="test.model"
+     targetProject="\MyProject\src">
+  <property name="enableSubPackages" value="true" />
+</sqlMapGenerator>
+
+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/table.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/table.xhtml new file mode 100644 index 0000000000..363c26b54b --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/table.xhtml @@ -0,0 +1,526 @@ + + + + + + The <table> Element + + + +

The <table> Element

+

The <table> element is used to select a table in the database for +introspection. Selected tables will cause the following objects to be generated +for each table:

+
    +
  • A MyBatis formatted SQL Map file
  • +
  • A set of classes that form the "model" of the table including: +
      +
    • A class to match the primary key of the table (if the table + has a primary key).
    • +
    • A class to match the fields in the table that are not in the + primary key, and non BLOB fields. This class will extend the + primary key if there is one.
    • +
    • A class to hold any BLOB fields in the table, if there are any. + This class will extend one of the two previous classes depending on the + configuration of the table.
    • +
    • A class that is used to generate dynamic where clauses in the + different "by example" methods (selectByExample, deleteByExample).
    • +
    +
  • +
  • (Optionally) A MyBatis mapper interface
  • +
+

At least one <table> element must be specified as a required child element +of the <context> element. +You can specify unlimited table elements.

+ +

Database Identifiers

+

MyBatis Generator (MBG) tries to deal with the case sensitivity of database identifiers automatically. +In most cases, MBG is able to find tables regardless of what you +specify for catalog, schema, and tableName +attributes. MBG's process follows these steps:

+
    +
  1. If either of the catalog, schema, or + tableName attributes contain a space, then MBG will + look for tables based on the exact case specified. In this case, MBG + will automatically delimit the table identifiers in the generated SQL.
  2. +
  3. Else if the database reports that identifiers are stored in upper case, + MBG will automatically convert any table identifier to upper case.
  4. +
  5. Else if the database reports that identifiers are stored in lower case, + MBG will automatically convert any table identifier to lower case.
  6. +
  7. Else MBG will look for tables based on the exact case specified.
  8. +
+

In most cases, this process works perfectly. However, there are cases where it will +fail. For example, suppose you create a table like this:

+
+  create table "myTable" (
+     ...some columns
+  )
+
+ +

Because the table name is delimited, most databases will create the +table with the exact case specified - even if the database normally stores +identifiers in upper case. In this instance, you should specify the attribute +delimitIdentifiers="true" in the table configuration.

+ +

Required Attributes

+ + + + + + + + + +
AttributeDescription
tableNameThe name of the database table (not including the schema or catalog). + The specified value can contain SQL wildcards if so desired. +
+ +

Optional Attributes

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeDescription
schemaThe database schema - not required if your database does not use schemas, + or if there is a default schema. + The specified value can contain SQL wildcards if so desired. +
catalogThe database catalog - not required if your database does not use catalogs, + or if there is a default catalog.
aliasThis attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"
+ If specified, this value will be used to alias the table and all column names in + any generated SQL select statement. Column names will be aliased with the pattern + alias_actualColumnName.
domainObjectNameThe base name from which generated object names will be generated. + If not specified, MBG will generate a name automatically based on + the tableName. The name (either specified here, or generated + automatically) will be used to compute generated domain class names + and DAO class names. +

You can specify a package fragment in the domain object name. For example, + if you specify foo.Bar then the domain object will be + Bar and package foo will be appended + to the target package specified in the generator configurations.

+
mapperNameThe name of the MyBatis3 generated mapper class and XML file. + If not specified, the name will be whatever the domain object name is, plus the + word "Mapper". +

You can specify a package fragment in the mapper name. For example, + if you specify foo.BarMapper then the mapper will be + BarMapper and package foo will be appended + to the target package specified in the generator configurations.

+

Since version 1.3.4

+
sqlProviderNameThis attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"
+ The name of the MyBatis3 generated SQL provider class (which may or may not be generated + based on the configuration). + If not specified, the name will be whatever the domain object name is, plus the + word "SqlProvider". +

You can specify a package fragment in the SQL provider name. For example, + if you specify foo.BarSqlProvider then the SQL provider will be + BarSqlProvider and package foo will be appended + to the target package specified in the generator configurations.

+

Since version 1.3.4

+
enableInsertThis attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"
+ Signifies whether an insert statement should be generated. +

The default is true.

enableSelectByPrimaryKeyThis attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"
+ Signifies whether a select by primary key statement should be generated. + Regardless of this setting, the statement will not be generated if the + table does not have a primary key. +

The default is true.

enableSelectByExampleThis attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"
+ Signifies whether a select by example statement should be generated. + This statement enables many different dynamic queries to be generated at run time. +

The default is true.

enableUpdateByPrimaryKeyThis attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"
+ Signifies whether an update by primary key statement should be generated. + Regardless of this setting, the statement will not be generated if the + table does not have a primary key. +

The default is true.

enableDeleteByPrimaryKeyThis attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"
+ Signifies whether an delete by primary key statement should be generated. + Regardless of this setting, the statement will not be generated if the + table does not have a primary key. +

The default is true.

enableDeleteByExampleThis attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"
+ Signifies whether a delete by example statement should be generated. + This statement enables many different dynamic deletes to be generated at run time. +

The default is true.

enableCountByExampleThis attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"
+ Signifies whether a count by example statement should be generated. + This statement will return the number of rows in a table that match + an example. +

The default is true.

enableUpdateByExampleThis attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"
+ Signifies whether an update by example statement should be generated. + This statement will update rows in a table that match + an example. + If true, an update by example "selective" statement will also be generated. + The "selective" statement will only update columns where the corresponding + value in the record parameter is non-null. +

The default is true.

selectByPrimaryKeyQueryIdThis attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"
+ This value will be added to the select list of the select by primary key statement + in this form: "'<value>' as QUERYID". + This can be useful for identifying queries in DBA tracing tools at run time. + If you use thus value, you should specify a unique id for every different query + generated by MBG.
selectByExampleQueryIdThis attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"
+ This value will be added to the select list of the select by example statement + in this form: "'<value>' as QUERYID". + This can be useful for identifying queries in DBA tracing tools at run time. + If you use thus value, you should specify a unique id for every different query + generated by MBG.
modelType + This attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"
+ This attribute is used to override the default model type if you desire + to do so for this table. If not specified, MBG will generate domain + objects based on the context default model type. + The model type defines how MBG will generate domain classes. With some + model types MBG will generate a single domain class for each table, + with others MBG may generate different classes depending on the structure + of the table. The property supports these values: + + + + + + + + + + + + + +
conditionalThis model is similar to the hierarchical model except that a separate + class will not be generated if that separate class would only contain + one field. So if a table has only one primary key field, that field + will be merged into the base record class.
flatThis model generates only one domain class for any table. The class + will hold all fields in the table.
hierarchicalThis model will generate a primary key class if the table has + a primary key, another class that holds any BLOB columns in the table, and + another class that holds the remaining fields. There is an appropriate + inheritance relationship between the classes.
+
escapeWildcardsSignifies whether SQL wildcards ('_' and '%') in the schema and tableName should + be escaped when searching for columns. This is required by some drivers if the + schema or tableName includes an SQL wildcard (for example, if a table name is + MY_TABLE, some drivers require that the underscore character be escaped). +

The default is false.

delimitIdentifiersSignifies whether MBG should use the exact case specified when searching + for tables and then delimit the identifiers in the generated SQL. See the + discussion above for more details. +

The delimiter characters are specified on the + <context> element.

+

The default is false unless the catalog, + schema, or tableName attributes + contain a space, then true.

delimitAllColumnsSignifies whether MBG should add delimiters to all column names in the generated + SQL. This is an alternative to coding a <columnOverride> + for every column + specifying that the column should be delimited. This is useful for databases + like PostgreSQL that are case sensitive with identifiers. +

The delimiter characters are specified on the + <context> element.

+

The default is false.

+ +

Child Elements

+ + +

Supported Properties

+

This table lists the properties of the default SQL Map generators that can be +specified with the <property> child element:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Property NameProperty Values
constructorBasedThis property is ignored is the target runtime is "MyBatis3Kotlin"
+ This property is used to select whether MyBatis Generator will generate a constructor + for the class that accepts a value for each field in the class. Also, the SQL result map + will be built to use the constructor rather than the "setter" for each field. +

This property is ignored (and forced "true") if the "immutable" property + is set "true".

+

The default value is false.

dynamicSqlSupportClassNameThis property is ignored unless the target runtime is "MyBatis3DynamicSQL" or "MyBatis3Kotlin"
+ The name of the generated MyBatis Dynamic SQL support class. + If not specified, the name will be whatever the domain object name is, plus the + word "DynamicSqlSupport". +

You can specify a package fragment in the support class name. For example, + if you specify foo.BarSqlSupport then the SQL provider will be + BarSqlSupport and package foo will be appended + to the package specified in the generator configuration.

+

Since version 1.4.1

+
dynamicSqlTableObjectNameThe name to use for the inner class generated in support classes for MyBatis Dynamic SQL. If not + specified, the name will be the calculated domain object name (typically the table name). The value + if this property will be used as is for the inner class name (case-sensitive). An outer class + property name will also be calculated from this name (typically with the initial letter lower-cased).
ignoreQualifiersAtRuntimeIf true, then + MBG will not add the schema or catalog to the table name in the generated SQL. + This is useful if you have tables with the same name in several schemas - + you can use MBG to generate objects based on the table in one schema, + but not include the schema for runtime.

+

The default value is false.

immutableThis property is ignored is the target runtime is "MyBatis3Kotlin"
+ This property is used to select whether MBG will generate immutable + model classes - this means that the classes will not have "setter" methods and + the constructor will accept values for each field in the class. +

If true, this forces the model classes to be built with paramterized constructors + regardless of the value of the "constructorBased" property.

+

The default value is false.

modelOnly + This property is used to select whether MBG will only generate + model classes for a table. +

If true, then a Java client will not be generated. + If an <sqlMapGenerator> is configured and this property is set true then + MBG will only generate result map elements in the SQL Mapper XML file for this table.

+

If true, then this value overrides any of the "enable*" attributes on the <table> + element - no CRUD methods will be generated.

+

The default value is false.

+
rootClassThis attribute is ignored if the target runtime is "MyBatis3Kotlin"
+ This property can be used to specify a root class for all generated + Java model objects. MBG will specify this value as the super class + of the primary key object, if the table has a primary key, or the + record object otherwise. The value specified in this property will override + the rootClass property set on the Java Model Generator + configuration if any is set. +

Important: If MBG is able to load the root class, it + will not override a property in the root class that exactly matches a + property that would normally be generated. + An exact match of a property is defined as follows

+
    +
  • Property name matches exactly
  • +
  • Property is of the same type
  • +
  • Property has a "getter" method
  • +
  • Property has a "setter" method
  • +
+

If specified, the value of this property should be a fully qualified + class name (like com.mycompany.MyRootClass).

rootInterfaceThis property is ignored if the target runtime is "MyBatis3Kotlin"
+ This property can be used to specify a super interface for all generated + DAO interface objects. The value specified in this property will override + the rootInterface property set on the Java Client Generator + configuration if any is set. +

Important: MBG does not verify that the interface exists, or is a + valid Java interface.

+

If specified, the value of this property should be a fully qualified + interface name (like com.mycompany.MyRootInterface).

runtimeCatalogIf you specify a value for this property, than MBG will use that + value as the catalog in the generated SQL rather than the catalog + as configured above. + This is useful if you want to generate code against one catalog, but + want to use a different catalog at runtime.
runtimeSchemaIf you specify a value for this property, than MBG will use that + value as the schema in the generated SQL rather than the schema + as configured above. + This is useful if you want to generate code against one schema, but + want to use a different schema at runtime.
runtimeTableNameIf you specify a value for this property, than MBG will use that + value as the table name in the generated SQL rather than the tableName + as configured above. + This is especially useful on Oracle if you want to generate objects to use + a public synonym. In that case, you will need to generate the objects against the + actual table that the synonym points to, then specify the synonym name in + this property. You should also specify the ignoreQualifiersAtRuntime + property in most cases with public synonyms.
selectAllOrderByClauseThis property can be used to specify an order by clause that will be added to + the selectAll method. This is only applicable if you are using the + MyBatis3Simple target runtime. MBG will prepend order by + to anything you specify in this property, so the property should contain + a column list only (e.g ID1, ID2 or ID1 desc, ID2 asc) +
trimStringsThis attribute is ignored is the target runtime is "MyBatis3Kotlin"
+

This property is used to select whether MyBatis Generator adds code to trim + the white space from character fields returned from the database. + This can be useful if your database stores data in CHAR fields rather than + VARCHAR fields. When true, MyBatis Generator will insert code to trim character fields. + Can be overridden with the trimStrings property in a <columnOverride> + configuration. This property value overrides the property if specified at the + <javaModelGenerator> level + and can be overridden for fields/columns using the property in a + <columnOverride> element.

+

The default value is inherited from the + <javaModelGenerator>, otherwise false.

useActualColumnNamesIf true, then + MBG will use column names as returned from the database metadata as the properties + of the generated domain objects. If false (default), MBG will attempt to camel + case the returned names. In either event, the name can be specified explicitly by the + <columnOverride> element in which case this property will be ignored for the + specified column. +

For example, suppose a table contains a column START_DATE. If the value of + this property is "true", then MBG will generate the property name + as START_DATE - meaning that the getters and setters for the value will be + getSTART_DATE() and setSTART_DATE(). + If the value of this property is false, then MBG will + generate the property name as startDate - meaning that the + getters and setters for the value will be getStartDate() and + setStartDate().

+

The default value is false.

useColumnIndexesThis property is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"
+ If true, then MBG will generate resultMaps that use column index rather than + column name in the result mappings. This is useful when a table has column names + differentiated only by the case of the name (e.g. "first name" and "First Name"). + There is a slight performance benefit with this support also.

+

The default value is false.

+

Important Note: This property is not supported if the target runtime is + for MyBatis version 3.

useCompoundPropertyNamesIf true, then + MBG will use generate property names by contatenating the column name with the + column reparks. This can be usefull in databases created by 4th generation languages + where the column names are generated (e.g. FLD2237), but the remarks contain useful + information (e.g. "customer id"). In this case, MBG will generate a property + name of FLD2237_CustomerId. +

The default value is false.

+ +

Example

+

This element specifies that we always want to generate code for +a table called MYTABLE in schema MYSCHEMA. We also want to ignore +a column called "fred" in the table, and we want to override the +column "BEG_DATE" so that the generated property name will be "startDate".

+
+<table tableName="MYTABLE" schema="MYSCHEMA">
+  <ignoreColumn column="fred"/>
+  <columnOverride column="BEG_DATE" property="startDate"/>
+</table>
+
+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/configreference/xmlconfig.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/xmlconfig.xhtml new file mode 100644 index 0000000000..68fbe7f5ec --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/configreference/xmlconfig.xhtml @@ -0,0 +1,149 @@ + + + + + + MyBatis Generator XML Configuration File Reference + + + +

MyBatis GeneratorXML Configuration File Reference

+

In the most common use case, MyBatis Generator (MBG) is driven by an XML + configuration file. The configuration file tells MBG:

+ +
    +
  • How to connect to the database
  • +
  • What objects to generate, and how to generate them
  • +
  • What tables should be used for object generation
  • +
+ +

The following is an example MBG configuration file. See the individual pages +for each element for more information about the elements and the values of the +attributes.

+
+<?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">
+
+<generatorConfiguration>
+  <classPathEntry location="/Program Files/IBM/SQLLIB/java/db2java.zip" />
+
+  <context id="DB2Tables" targetRuntime="MyBatis3">
+    <jdbcConnection driverClass="COM.ibm.db2.jdbc.app.DB2Driver"
+        connectionURL="jdbc:db2:TEST"
+        userId="db2admin"
+        password="db2admin">
+    </jdbcConnection>
+
+    <javaTypeResolver >
+      <property name="forceBigDecimals" value="false" />
+    </javaTypeResolver>
+
+    <javaModelGenerator targetPackage="test.model" targetProject="\MBGTestProject\src">
+      <property name="enableSubPackages" value="true" />
+      <property name="trimStrings" value="true" />
+    </javaModelGenerator>
+
+    <sqlMapGenerator targetPackage="test.xml"  targetProject="\MBGTestProject\src">
+      <property name="enableSubPackages" value="true" />
+    </sqlMapGenerator>
+
+    <javaClientGenerator type="XMLMAPPER" targetPackage="test.dao"  targetProject="\MBGTestProject\src">
+      <property name="enableSubPackages" value="true" />
+    </javaClientGenerator>
+
+    <table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" >
+      <property name="useActualColumnNames" value="true"/>
+      <generatedKey column="ID" sqlStatement="DB2" identity="true" />
+      <columnOverride column="DATE_FIELD" property="startDate" />
+      <ignoreColumn column="FRED" />
+      <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />
+    </table>
+
+  </context>
+</generatorConfiguration>
+
+
+

Important notes about this file follow:

+
    +
  • The file specifies that the legacy DB2 CLI driver will be used to connect to the database, + and also specifies where the driver can be found.
  • +
  • The Java Type Resolver should not force the use of BigDecimal fields - this means that + integral types (Short, Integer, Long, etc.) will be substituted if possible. This feature + is an attempt to make database DECIMAL and NUMERIC columns easier to deal with.
  • +
  • The Java model generator should use sub-packages. This means that the generated model + objects will be placed in a package called test.model.db2admin in this case + (because the table + is in the DB2ADMIN schema). If the enableSubPackages attribute was set to + false, + then the package would be test.model. The Java model generator should + also trim strings. + This means that the setters for any String properties will call the trim + function - + this is useful if your database might return blank characters at the end of character + columns.
  • +
  • The SQL Map generator should use sub-packages. This means that the generated XML files + will be placed in a package called test.xml.db2admin in this case + (because the table + is in the DB2ADMIN schema). If the enableSubPackages attribute was set + to false, + then the package would be test.xml.
  • +
  • The DAO generator should use sub-packages. This means that the generated DAO classes + will be placed in a package called test.dao.db2admin in this case + (because the table + is in the DB2ADMIN schema). If the enableSubPackages attribute was set + to false, + then the package would be test.dao. The DAO generator should generate + mapper interfaces that reference an XML configuration for MyBatis. +
  • +
  • The file specifies only one table will be introspected, but many more could be specified. + Important notes about the specified table include: +
      +
    • The generated objects will be based on the name Customer (CustomerKey, + Customer, + CustomerMapper, etc.) - rather than on the table name.
    • +
    • Actual column names will be used as properties. If this property were set to + false (or not specified), then MBG would attempt to camel case + the column + names. In either case, the name can be overridden by the + <columnOverride> + element
    • +
    • The column has a generated key, it is an identity column, and the database type is DB2. + This will cause + MBG to generate the proper + <selectKey> element in the generated + <insert> + statement so that the newly generated key can be returned (using DB2 specific SQL).
    • +
    • The column DATE_FIELD will be mapped to a property called + startDate. This will + override the default property which would be + DATE_FIELD in this case, or dateField + if the useActualColumnNames property was set to + false.
    • +
    • The column FRED will be ignored. No SQL will list the field, + and no Java property will be generated.
    • +
    • The column LONG_VARCHAR_FIELD will be treated as a + VARCHAR field, regardless of the actual data type.
    • +
    +
  • +
+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/dynamicSql.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/dynamicSql.xhtml new file mode 100644 index 0000000000..ae0ed19f61 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/dynamicSql.xhtml @@ -0,0 +1,234 @@ + + + + + + MyBatis Dynamic SQL Usage Notes + + + +

MyBatis Dynamic SQL Usage Notes

+

This page is a short introduction to using the classes generated for the MyBatis3DynamicSQL runtime. These classes +are dependent on the MyBatis Dynamic SQL +library. Please refer to that site for full information +about how the library works.

+ +

For each introspected table, the generator will generate three objects:

+
    +
  1. A "record" class that represents a row in the table. This is the same as other runtimes
  2. +
  3. A "support" class that includes a table definition and column definitions for the database table
  4. +
  5. A mapper interface with all the typical methods generated by the other runtimes.
  6. +
+ +

Important notes about the generated objects:

+
    +
  • No XML is generated
  • +
  • No separate "Example" class is generated
  • +
  • There are no separate "with BLOBs" and "without BLOBs" methods. If your table includes BLOB fields, then + they are included in all operations.
  • +
  • Model classes are always generated in the "flat" model meaning there is no separate primary key class or BLOBs class
  • +
  • Java 8 or higher is required
  • +
  • MyBatis 3.4.2 or higher is required
  • +
  • MyBatis Dynamic SQL 1.3.1 or higher is required
  • +
+ +

Format of the "Support" classes

+

A "support" class is created for each table. The support class includes a definition of the table and all the columns +in the table. These items are used as input to the code generated in the mappers - most often for the where clauses you +will write.

+ +

For example, suppose there is a table "TABLE_CODE" in schema "MYSCHEMA". Further suppose that table has "ID" and +"DESCRIPTION" columns. The generated support class will look like this:

+ +
+package example;
+
+import java.sql.JDBCType;
+import org.mybatis.dynamic.sql.SqlColumn;
+import org.mybatis.dynamic.sql.SqlTable;
+
+public final class TableCodeDynamicSqlSupport {
+    public static final TableCode tableCode = new TableCode();
+    public static final SqlColumn<Integer> id = tableCode.id;
+    public static final SqlColumn<String> description = tableCode.description;
+
+    public static final class TableCode extends AliasableSqlTable<TableCode> {
+        public final SqlColumn<Integer> id = column("ID", JDBCType.INTEGER);
+        public final SqlColumn<String> description = column("DESCRIPTION", JDBCType.VARCHAR);
+
+        public TableCode() {
+            super("MYSCHEMA.TABLE_CODE", TableCode::new);
+        }
+    }
+}
+
+ +

In your code, it is typical to import the static elements of this support class so they can be used directly in the +code you write. With this static import you can refer to the fields +in either a direct or qualified manner - "id" or "tableCode.id".

+ +

Usage of the Mapper Classes

+

The following methods work the same as the other runtimes and we won't cover them here:

+
    +
  • deleteByPrimaryKey
  • +
  • insert - insert a single row (will insert nulls)
  • +
  • insertMultiple - insert multiple rows (will insert nulls)
  • +
  • insertSelective - insert a single row and ignore null properties
  • +
  • selectByPrimaryKey
  • +
  • updateByPrimaryKey - will set null values
  • +
  • updateByPrimaryKey Selective - ignores null values
  • +
+ +

There are no "by example" methods. Instead, there are general purpose methods that allow you to specify a + where clause with a lambda. The generator will create the following general methods:

+
    +
  • count
  • +
  • delete
  • +
  • select
  • +
  • selectDistinct
  • +
  • selectOne
  • +
  • update
  • +
+ +

Each of these methods includes support for a very flexible WHERE clause that can be specified with a lambda. If you +don't need a where clauses, there are utility functions that mean "all rows".

+ +

For example, you can retrieve the total number of rows in a table by calling the count method without a WHERE clause. +That code looks like this:

+ +
+  long totalRows = mapper.count(c -> c);
+
+ +Or... + +
+  long totalRows = mapper.count(CountDSLCompleter.allRows());
+
+ +

You can retrieve all rows in a table by calling select without a WHERE clause like this:

+ +
+  List<TableCode> allRecords = mapper.select(c -> c);
+
+ +Or... + +
+  List<TableCode> allRecords = mapper.select(SelectDSLCompleter.allRows());
+
+ +

It is far more interesting to add WHERE clauses to these methods. To add support for WHERE clauses, you should import the static +elements from the support class as shown above, and you should also import the SqlBuilder support. Then you can code arbitrarily +complex where clauses, and "ORDER BY" phrases as shown below:

+ +
+import static example.TableCodeDynamicSqlSupport.*;  // import the generated "support" items
+import static org.mybatis.dynamic.sql.SqlBuilder.*;  // import MyBatis Dynamic SQL where support
+
+public class SomeService {
+
+    public void simpleWhere() {
+        ...
+        // Simple WHERE clause
+        List<TableCode> records = mapper.select(c ->
+                c.where(id, isEqualTo(3)));
+        ...
+    }
+
+    public void complexWhere1() {
+        ...
+        // Simple WHERE clause with OR
+        List<TableCode> records = mapper.select(c ->
+                c.where(id, isEqualTo(3))
+                .or(description, isLike("f%")));
+        ...
+    }
+
+    public void complexWhere2() {
+        ...
+        // complex WHERE and ORDER BY
+        List<TableCode> records = mapper.select(c ->
+                c.where(id, isLessThan(10), and(description, isEqualTo("foo")))
+                .or(description, isLike("b%"))
+                .orderBy(id.descending()));        
+        ...
+    }
+}
+
+ +

Update Method Usage

+

The generated update statement is very flexible. You can now create any arbitrary update, +as well as updates that mimic the old updateByExample and updateByExampleSelective methods.

+ +
+import static example.TableCodeDynamicSqlSupport.*;  // import the generated "support" items
+import static org.mybatis.dynamic.sql.SqlBuilder.*;  // import MyBatis Dynamic SQL where support
+
+public class SomeService {
+
+    public void simpleUpdate() {
+        ...
+        // Flexible update - no backing record needed
+        int rows = mapper.update(c ->
+                c.set(id).equalTo(1)
+                .set(description).equalToNull()
+                .where(id, isEqualTo(3)));
+        ...
+    }
+
+    public void updateByExample(TableCode row) {
+        ...
+        // Update like the old updateByExample method
+        int rows =  mapper.update(c ->
+                TableCodeMapper.updateAllColumns(row, c)
+                .where(id, isEqualTo(3))
+                .or(description, isLike("f%")));
+        ...
+    }
+
+    public void updateByExampleSelective(TableCode row) {
+        ...
+        // Update like the old updateByExampleSelective method
+        int rows =  mapper.update(c ->
+                TableCodeMapper.updateSelectiveColumns(row, c)
+                .where(id, isEqualTo(3))
+                .or(description, isLike("f%")));
+        ...
+    }
+}
+
+ +

New Plugins

+

Because the *ByExample methods are removed, it no longer makes sense to control method generation via the properties +on an XML <table> configuration like enableInsert, +enableSelectByExample, etc. So this new runtime will ignore any of those properties. If you wish +to have this level of control over what is generated, you can accomplish that with a plugin. We have also included +the following new plugins for general use with this runtime:

+
    +
  • org.mybatis.generator.plugins.dsql.DisableDeletePlugin - disables all generated delete methods
  • +
  • org.mybatis.generator.plugins.dsql.DisableInsertPlugin - disables all generated insert methods
  • +
  • org.mybatis.generator.plugins.dsql.DisableUpdatePlugin - disables all generated update methods
  • +
  • org.mybatis.generator.plugins.dsql.ReadOnlyPlugin - disables all generated delete, insert, + and update methods
  • +
+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/dynamicSqlKotlin.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/dynamicSqlKotlin.xhtml new file mode 100644 index 0000000000..a17cc5d57b --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/dynamicSqlKotlin.xhtml @@ -0,0 +1,238 @@ + + + + + + MyBatis Dynamic SQL with Kotlin Usage Notes + + + +

MyBatis Dynamic SQL with Kotlin Usage Notes

+

This page is a short introduction to using the classes generated for the MyBatis3Kotlin runtime +These classes +are dependent on the MyBatis Dynamic SQL +library version 1.1.4 or higher. Please refer to that site for full information +about how the library works. In particular, see the +Kotlin Usage Page for full details.

+ +

Generated Files

+

For each introspected table, the generator will generate three Kotlin files:

+
    +
  1. A Kotlin data class that represents a row in the table. By default, the class will be named based + on the table name
  2. +
  3. A "support" class that includes a table definition and column definitions for the database table
  4. +
  5. A mapper interface with the basic MyBatis mapper methods and extension methods that simplify reuse of the basic + mapper methods. This is similar to the default interface methods generated in the other runtimes, but it is accomplished + with extension methods in Kotlin. +
  6. +
+ +

Important notes about the generated objects:

+
    +
  • No XML is generated
  • +
  • No separate "Example" class is generated
  • +
  • There are no separate "with BLOBs" and "without BLOBs" methods. If your table includes BLOB fields, then + they are included in all operations.
  • +
  • Model classes are always generated in the "flat" model meaning there is no separate primary key class or BLOBs class
  • +
  • Java 8 or higher is required
  • +
  • Any recent version of Kotlin should work
  • +
  • MyBatis 3.4.2 or higher is required
  • +
  • MyBatis Dynamic SQL 1.4.0 or higher is required
  • +
+ +

Format of the "Support" classes

+

A "support" class is created for each table. The support class includes a definition of the table and all the columns +in the table. These items are used as input to the code generated in the mappers - most often for the where clauses you +will write.

+ +

For example, suppose there is a table "TABLE_CODE" in schema "MYSCHEMA". Further suppose that table has "ID" and +"DESCRIPTION" columns. The generated support class will look like this:

+ +
+package example
+
+import java.sql.JDBCType
+import org.mybatis.dynamic.sql.AliasableSqlTable
+import org.mybatis.dynamic.sql.util.kotlin.elements.column
+
+object TableCodeDynamicSqlSupport {
+    val tableCode = TableCode()
+    val id = tableCode.id
+    val description = tableCode.description
+
+    class TableCode : AliasableSqlTable<TableCode>("MYSCHEMA.TABLE_CODE", ::TableCode) {
+        val id = column<Int>(name = "ID", jdbcType = JDBCType.INTEGER)
+        val description = column<String>(name = "DESCRIPTION", jdbcType = JDBCType.VARCHAR)
+    }
+}
+
+ +

In your code you can import that table object and/or each generated column (Kotlin does not support a star "*" import in this case). +With these imports you can refer to the fields +in either a direct or qualified manner - "id" or "tableCode.id".

+ +

Usage of the Mapper Classes

+

The following methods work the same as the other runtimes and we won't cover them here:

+
    +
  • deleteByPrimaryKey
  • +
  • insert - insert a single row (will insert nulls)
  • +
  • insertMultiple - insert multiple rows (will insert nulls)
  • +
  • insertSelective - insert a single row and ignore null properties
  • +
  • selectByPrimaryKey
  • +
  • updateByPrimaryKey - will set null values
  • +
  • updateByPrimaryKey Selective - ignores null values
  • +
+ +

There are no "by example" methods. Instead, there are general purpose methods that allow you to specify a +where clause with a lambda. The generator will create the following general methods:

+
    +
  • count
  • +
  • delete
  • +
  • select
  • +
  • selectDistinct
  • +
  • selectOne
  • +
  • update
  • +
+ +

Each of these methods includes support for a very flexible WHERE clause that can be specified with a lambda. If you +don't need a where clauses, there are utility functions that mean "all rows".

+ +

For example, you can retrieve the total number of rows in a table by calling the count method without a WHERE clause. +That code looks like this:

+ +
+  val totalRows = mapper.count { allRows() }
+
+ + +

You can retrieve all rows in a table by calling select without a WHERE clause like this:

+ +
+  val allRecords = mapper.select { allRows() }
+
+ +

It is far more interesting to add WHERE clauses to these methods. To add support for WHERE clauses, you should import the +elements from the support class as shown above, and you should also import the SqlBuilder support. Then you can code arbitrarily +complex where clauses, and "ORDER BY" phrases as shown below:

+ +
+// import the generated "support" items...
+import example.TableCodeDynamicSqlSupport.description
+import example.TableCodeDynamicSqlSupport.id
+
+class SomeService {
+
+    fun simpleWhere() {
+        ...
+        // Simple WHERE clause
+        val records = mapper.select {
+            where { id isEqualTo 3 }
+        }
+        ...
+    }
+
+    fun complexWhere1() {
+        ...
+        // Simple WHERE clause with OR
+        val records = mapper.select {
+            where { id isEqualTo 3 }
+            or { description isLike "f%" }
+        }
+        ...
+    }
+
+    fun complexWhere2() {
+        ...
+        // complex WHERE and ORDER BY
+        val records = mapper.select {
+            where {
+                id isLessThan 10
+                and { description isEqualTo "foo" }
+            }
+            or { description isLike "b%" }
+            orderBy(id.descending())
+        }        
+        ...
+    }
+}
+
+ +

Update Method Usage

+

The generated update statement is very flexible. You can now create any arbitrary update, +as well as updates that mimic the old updateByExample and updateByExampleSelective methods.

+ +
+// import the generated "support" items...
+import example.TableCodeDynamicSqlSupport.description
+import example.TableCodeDynamicSqlSupport.id
+
+class SomeService {
+
+    fun simpleUpdate() {
+        ...
+        // Flexible update - no backing record needed
+        val rows = mapper.update {
+            set(id) equalTo 1
+            set(description).equalToNull()
+            where { id isEqualTo 3 }
+        }
+        ...
+    }
+
+    fun updateByExample(row: TableCode) {
+        ...
+        // Update like the old updateByExample method
+        val rows =  mapper.update {
+            updateAllColumns(row)
+            where { id isEqualTo 3 }
+            or { description isLike "f%" }
+        }
+        ...
+    }
+
+    fun updateByExampleSelective(row: TableCode) {
+        ...
+        // Update like the old updateByExampleSelective method
+        val rows =  mapper.update {
+            updateSelectiveColumns(row)
+            where { id isEqualTo 3 }
+            or { description isLike "f%" }
+        }
+        ...
+    }
+}
+
+ +

New Plugins

+

Because the *ByExample methods are not generated, it no longer makes sense to control method generation via the properties +on an XML <table> configuration like enableInsert, +enableSelectByExample, etc. So this new runtime will ignore any of those properties. If you wish +to have this level of control over what is generated, you can accomplish that with a plugin. We have also included +the following plugins for general use with this runtime:

+
    +
  • org.mybatis.generator.plugins.dsql.DisableDeletePlugin - disables all generated delete methods
  • +
  • org.mybatis.generator.plugins.dsql.DisableInsertPlugin - disables all generated insert methods
  • +
  • org.mybatis.generator.plugins.dsql.DisableUpdatePlugin - disables all generated update methods
  • +
  • org.mybatis.generator.plugins.dsql.ReadOnlyPlugin - disables all generated delete, insert, + and update methods
  • +
+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/exampleClassUsage.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/exampleClassUsage.xhtml new file mode 100644 index 0000000000..595e05326a --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/exampleClassUsage.xhtml @@ -0,0 +1,147 @@ + + + + + + Example Class Usage Notes + + + +

Example Class Usage Notes

+

The example class specifies how to build a dynamic where clause. Each non-BLOB column in the +table can optionally be included in the where clause. Examples are the best way +to demonstrate the usage of this class.

+

The example class can be used to generate a virtually +unlimited where clauses.

+

The example classes contain +an inner static class called Criteria +that holds a list of conditions that will be anded together in the where clause. The +example class holds a list of Criteria objects and all the clauses +from the inner classes will be ored together. Using different sets of +Criteria classes allows you to generate virtually unlimited +types of where clauses.

+

Criteria objects can be created with the either the createCriteria method +or the or method +in the example class. When the first Criteria object is created with the +createCriteria method it is automatically +added to the list of Criteria objects - this makes it easy to write +a simple where clause if you don't need to or several other clauses together. +When using the or method, the Criteria class is added to the +list in all instances.

+ +

Important We recommend that +you only use the or method for creating Criteria classes. We +believe that this method makes for more readable code.

+ +

Simple Queries

+

This example shows how to generate a simple WHERE clause using the generated +example class:

+ +
+  TestTableExample example = new TestTableExample();
+
+  example.createCriteria().andField1EqualTo(5);
+
+ +

Alternatively, the following syntax also works:

+
+  TestTableExample example = new TestTableExample();
+
+  example.or().andField1EqualTo(5);
+
+ +

In either above example, the dynamically generated where clause will effectively be:

+
+  where field1 = 5
+
+ +

Complex Queries

+

The next example shows how to generate a complex WHERE clause using the generated +example class (using JSE 5.0 parameterized types):

+
+  TestTableExample example = new TestTableExample();
+
+  example.or()
+    .andField1EqualTo(5)
+    .andField2IsNull();
+
+  example.or()
+    .andField3NotEqualTo(9)
+    .andField4IsNotNull();
+
+  List<Integer> field5Values = new ArrayList<Integer>();
+  field5Values.add(8);
+  field5Values.add(11);
+  field5Values.add(14);
+  field5Values.add(22);
+
+  example.or()
+    .andField5In(field5Values);
+
+  example.or()
+    .andField6Between(3, 7);
+
+
+

In the above example, the dynamically generated where clause will effectively be:

+
+  where (field1 = 5 and field2 is null)
+     or (field3 <> 9 and field4 is not null)
+     or (field5 in (8, 11, 14, 22))
+     or (field6 between 3 and 7)
+
+

Returned records will meet these criteria.

+ +

Distinct Queries

+

You can force queries to be DISTINCT by calling the setDistinct(true) +method on any example class.

+ +

Criteria Classes

+

The Criteria inner class includes andXXX methods for each field, +and each standard SQL predicate including:

+
    +
  • IS NULL - meaning the related column must be NULL
  • +
  • IS NOT NULL - meaning the related column must not be NULL
  • +
  • = (equal) - meaning the related column must be equal to the value passed in on the method call
  • +
  • <> (not equal) - meaning the related column must not be equal to the value passed in on the method call
  • +
  • > (greater than) - meaning the related column must be greater than the value passed in on the method call
  • +
  • >= (greater than or equal) - meaning the related column must be greater than or equal to the value passed in on the method call
  • +
  • < (less than) - meaning the related column must be less than the value passed in on the method call
  • +
  • <= (less than or equal) - meaning the related column must be less than or equal to the value passed in on the method call
  • +
  • LIKE - meaning the related column must be "like" the value passed in on the method call. + The code does not add the required '%', you must set that value yourself in the value you pass + in on the method call. +
  • +
  • NOT LIKE - meaning the related column must be "not like" the value passed in on the method call. + The code does not add the required '%', you must set that value yourself in the value you pass + in on the method call. +
  • +
  • BETWEEN - meaning the related column must be "between" the two values passed in on + the method call.
  • +
  • NOT BETWEEN - meaning the related column must be "not between" the two values passed in on + the method call.
  • +
  • IN - meaning the related column must be one of the list of values passed in on + the method call.
  • +
  • NOT IN - meaning the related column must not be one of the list of values passed in on + the method call.
  • +
+ + + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/extendingExampleClass.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/extendingExampleClass.xhtml new file mode 100644 index 0000000000..bfa3ca8b6f --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/extendingExampleClass.xhtml @@ -0,0 +1,217 @@ + + + + + + Extending the Example Classes + + + +

Extending the Example Classes

+

In some cases it may be desirable to extended the generated example classes. +You may want to add criterion that are specific to your database (such as Oracle +ROWNUM support), or add criterion that are not automatically generated (such as +a case insensitive search). In situations like these, you may extend the generated +example class to add these additional criteria.

+ +

General Principles

+

MyBatis Generator (MBG) generates an "example" class for each table, unless instructed otherwise +in the configuration. The "example" class is used to generate a dynamic where +clause for use in the xxxByExample statements. +The standard "example" class includes functionality for all standard SQL predicates. +In some cases, it may be desirable to add additional predicates for the +specific needs of your application. This may include adding support for non-standard +predicates, or for using database specific functions in your where clauses.

+ +

The generated "example" class includes a nested inner class where the actual +functionality of the predicates exists. This inner class is always named GeneratedCriteria. +MBG also generates an inner class named Criteria which extends +GeneratedCriteria and which you may +use for adding your own functions to the example classes. The Criteria +class will not be deleted by the Eclipse Java code merger, so you may add to it without +fear of losing your changes upon regeneration.

+

For example, suppose there is a +table called CUSTOMER. Typically, MBG would generate a class named +CustomerExample. To add functionality to the CustomerExample class, you +should add additional methods to the CustomerExample.Criteria class.

+ +

Extending vs. Plugging In

+

If you find that you are extending the example classes frequently, it might be +more convenient for you to create a plugin to generate the additional +functionality rather than hand coding the extended classes. The example below (under +the heading "Single Parameter Predicates") can also be accomplished with a plugin +as demonstrated by the class +org.mybatis.generator.plugins.CaseInsensitiveLikePlugin.

+ +

Adding Predicates

+

MBG generates a dynamic SQL fragment that allows virtually unlimited +where clauses to be created at run-time. To accomplish this, the generated SQL +fragment supports four broad types of SQL predicates. For each type of +SQL predicate, there is a corresponding method in the GeneratedCriteria +inner class +that can be used to add a predicate to the dynamic where clause.

+ +

1. Simple String Substitution

+

This type of predicate is used when there is no need for a property +from the parameter object to be substituted into the where clause. Examples +include:

+

FIRST_NAME is null
+ LAST_NAME is not null

+ +

The GeneratedCriteria class method for this predicate is:

+   addCriterion(String anyString) + +

Where "anyString" is the string to be substituted into the where clauses. +This method can be used to add any kind of test to the generated where clause.

+ +

For example, suppose you wanted to use the SOUNDEX function to do a "sounds like" +name search. In MySQL, the predicate should look like this:

+SOUNDEX(FIRST_NAME) = SOUNDEX('frod') +

This predicate is too complex to use one of the other methods, so it must +be inserted into the where clause by simple string substitution. Add the following +method to the Criteria inner class for this functionality:

+
+public Criteria andFirstNameSoundsLike(String value) {
+  StringBuffer sb = new StringBuffer("SOUNDEX(FIRST_NAME) = SOUNDEX('");
+  sb.append(value);
+  sb.append("')");
+
+  addCriterion(sb.toString());
+
+  return this;
+}
+
+ +

The following code shows the use of this new functionality with the selectByExample method:

+
+CustomerExample example = new CustomerExample();
+Criteria criteria = example.createCriteria();
+criteria.andFirstNameSoundsLike("frod");
+List results = selectByExample(example);
+
+ +

This method can be used to add virtually any predicate to a where clause. +However, it is generally better to use parameter substitution if possible because +the problems of formatting different data types properly (most notably +dates, times, and timestamps). Also, there is a chance of SQL +injection issues with this method if you expose a too generic method. +If possible, we suggest using one of the other methods listed below.

+ +

2. Single Parameter Predicates

+

This type of predicate is used when there is a single property + from the parameter object to be substituted into the where clause. Examples + include

+

FIRST_NAME = ?
+ LAST_NAME <> ?

+ +

The generated Criteria class method for this predicate is:

+

   addCriterion(String anyString, Object anyObject, String propertyName)

+ +

Where:

+
+
anyString
+
is the string to be substituted into the where clause before a parameter substitution
+
anyObject
+
is the Object to be substituted into the where clause after the string substitution
+
propertyName
+
is a string denoting the property name related to this clause. This String is only used + in potential error messages.
+
+ +

This method can be used to add simple tests related to a single parameter to the generated where clause.

+ +

For example, suppose you wanted to perform a case insensitive search on certain columns. +In MySQL, the predicate could look like this:

+upper(FIRST_NAME) like ? +

This predicate fits the capabilities of a single parameter predicate - where the predicate +is a string value followed by a single parameter. Add the following +method to the ExtendedCriteria for this functionality:

+
+public ExtendedCriteria andFirstNameLikeInsensitive(String value) {
+  addCriterion("upper(FIRST_NAME) like",
+    value.toUpperCase(), "firstName");
+
+  return this;
+}
+
+ +

The following code shows the use of this new functionality with the selectByExample method:

+
+ExtendedExample example = new ExtendedExample();
+ExtendedCriteria criteria = (ExtendedCriteria) example.createCriteria();
+criteria.andFirstNameLikeInsensitive("fred%");
+List results = selectByExample(example);
+
+ +

3. List Predicates

+

List predicates are used to add a variable sized list of values as parameters to a where +clause. Examples include:

+

FIRST_NAME IN (?, ?, ?)
+LAST_NAME NOT IN (?, ?, ?, ?)

+ +

This predicate is less flexible then the others because it is included specifically +for the "in" and "not in" standard predicates. Nevertheless, if you find some use for it +the corresponding method in the Criteria class is as follows:

+ +

   addCriterion(String anyString, List listOfObjects, String propertyName)

+ +

Where:

+
+
anyString
+
is the string to be substituted into the where clause before a parameter substitution
+
listOfObjects
+
is the List of Objects to be substituted into the where clause after the string substitution + (an open parenthesis will be appended before the list, list items will be comma delimited, + and a close parenthesis will be appended after the list).
+
propertyName
+
is a string denoting the property name related to this clause. This String is only used + in potential error messages.
+
+ +

4. Between Predicates

+

Between predicates are used to add a two parameters to a where +clause in a specific format. Examples include:

+

FIRST_NAME BETWEEN ? AND ?
+LAST_NAME NOT BETWEEN ? AND ?

+ +

This predicate is less flexible then the others because it is included specifically +for the "between" and "not between" standard predicates. Nevertheless, if you find some use for it +the corresponding method in the Criteria class is as follows:

+ +

   addCriterion(String anyString, Object object1, Object object2, String propertyName)

+ +

Where:

+
+
anyString
+
is the string to be substituted into the where clause before a parameter substitution
+
object1
+
is the objects to be substituted into the where clause after the string substitution + (the word "and" will be appended after this object).
+
object2
+
is the objects to be substituted into the where clause after the word "and".
+
propertyName
+
is a string denoting the property name related to this clause. This String is only used + in potential error messages.
+
+ + + + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/javaclient.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/javaclient.xhtml new file mode 100644 index 0000000000..1cd6a58e16 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/javaclient.xhtml @@ -0,0 +1,93 @@ + + + + + + MyBatis Generator Generated Java Client Objects + + + +

MyBatis Generator Generated Java Client Objects

+

MyBatis Generator (MBG) generates Java client objects that +are used to make interaction with the generated XML elements much easier. +For each table in the configuration, MBG generates a MyBatis mapper interface. +Generating Java client objects is optional, and is controlled by the +<javaClientGenerator> configuration element.

+ +

Every field and method generated includes the non-standard JavaDoc tag +@mbg.generated. When run from the Eclipse plugin, +on subsequent runs every field and method that +includes this JavaDoc tag will be deleted and replaced. Any other field or method in the +class will be untouched. +With this in mind, you can add other fields and methods to the classes without fear of losing them in +subsequent runs - simply DO NOT include the @mbg.generated +JavaDoc tag on anything that you add to the class.

+ +

Outside of the Eclipse plugin, Java files need to be merged by hand, but you can use the +@mbg.generated JavaDoc tag to know what is safe to delete from a prior +version of a file.

+ +

Note: in the following descriptions, the term "BLOB" is used to refer to any column +with a data type of BLOB, CLOB, LONGVARCHAR, or LONGVARBINARY.

+ +

Client Methods

+

Depending on the specifics of the table, and the configuration options, the Java client generator +will generate these methods:

+
    +
  • countByExample
  • +
  • deleteByPrimaryKey
  • +
  • deleteByExample
  • +
  • insert
  • +
  • insertSelective
  • +
  • selectByPrimaryKey
  • +
  • selectByExample
  • +
  • selectByExampleWithBLOBs
  • +
  • updateByPrimaryKey (with an override to specify whether or not to update BLOB columns)
  • +
  • updateByPrimaryKeySelective (will only update non-null fields in the parameter class)
  • +
  • updateByExample (with an override to specify whether or not to update BLOB columns)
  • +
  • updateByExampleSelective (will only update non-null fields in the parameter class)
  • +
+

MBG attempts to make it easier to deal with tables that contain BLOBs by generating +different objects and methods so that you can use the BLOB fields, or ignore them, depending +on the situation.

+

See the +Example Class Usage +page for an example of using the selectByExample method.

+ +

Client Usage in MyBatis

+

MyBatis mappers are interfaces that will map to +methods in the generated XML mapper files (if you have chosen to generated XML). If you have chosen an annotated +mapper, then the mapper interface contains all the generated code within itself. For example, suppose that MBG generated +an interface called MyTableMapper. You can use the interface as follows:

+
+  SqlSession sqlSession = sqlSessionFactory.openSession();
+
+  try {
+    MyTableMapper mapper = sqlSession.getMapper(MyTableMapper.class);
+    List<MyTable> allRecords = mapper.selectByExample(null);
+  } finally {
+    sqlSession.close();
+  }
+
+

See the standard MyBatis documentation for details on how to create the instance +of sqlSessionFactory.

+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/javamodel.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/javamodel.xhtml new file mode 100644 index 0000000000..8008cf7f84 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/javamodel.xhtml @@ -0,0 +1,141 @@ + + + + + + MyBatis Generator Generated Java Model Classes + + + +

MyBatis Generator Generated Java Model Classes

+

MyBatis Generator (MBG) generates Java classes that correspond to the fields in a database table. +The generated classes are a type of domain object, but should in no way be confused +with a rich domain model (see the Philosophy page +for more on this subject). MBG generates different types of "domain" objects based on +the characteristics of the table and configuration options.

+ +

Every field and method generated by MBG includes the non-standard JavaDoc tag +@mbg.generated. When run from the Eclipse plugin, +on subsequent runs of MBG every Java element that +includes this JavaDoc tag will be deleted and replaced. Any other Java element in the +class will be untouched by MBG. +With this in mind, you can add other fields and methods to the classes without fear of losing them in +subsequent runs of MBG - simply DO NOT include the @mbg.generated +JavaDoc tag on anything that you add to the class.

+

Outside of the Eclipse plugin, Java files need to be merged by hand, but you can use the +@mbg.generated JavaDoc tag to know what is safe to delete from a prior +version of a file.

+

The following sections describe the different types of "domain" classes that will be +generated. MBG will generate different types of domain classes depending +on the value of the defaultModelType attribute of the +<context> +configuration element and the modelType attribute of the +<table> +configuration element.

+ +

Any column ignored by an +<ignoreColumn> +configuration element will +by ignored and not added to any generated Java class.

+ +

Note: in the following descriptions, the term "BLOB" is used to refer to any column +with a data type of BLOB, CLOB, LONGVARCHAR, or LONGVARBINARY.

+ +

Primary Key Class

+

This class will contain properties for each field in the primary key of a table. +The property names will be generated automatically, and will be based on the column name +in the table. The generated property names can be overridden with a +<columnOverride> configuration element. +

+

The name of the class will be «TableName»Key by default, or +«domainObjectName»Key if the domainObjectName +attribute is specified on the <table> configuration element.

+ +

This class will be generated in the hierarchical model if the table has a primary key. +This class will be generated in the conditional model if the table has more +then one column in the primary key. This class will not be generated in the flat +model.

+ +

Record Class

+

This class will contain properties for each non-BLOB and non-primary key column in the table. +The class will extend the primary key class if there is one. +The property names will be generated automatically, and will be based on the column name +in the table. The generated property names can be overridden with a +<columnOverride> configuration element.

+ +

The name of the class will be «TableName» by default, or +«domainObjectName» if the domainObjectName +attribute is specified on the <table> configuration element.

+ +

This class will be generated in the hierarchical model if the table has non-BLOB +and non-primary key columns. This class will be generated in the conditional model +if the table has non-BLOB and non-primary key columns, or if there is only +one primary key column or one BLOB column. This class is always generated in the +flat model.

+ +

Record With BLOBs Class

+

This class will contain properties for each BLOB column in the table. +The class will extend the record class, if there is one, +or it will extend the primary key class (note that MBG does not support +tables that only contain BLOB columns). +The property names will be generated automatically, and will be based on the column name +in the table. The generated property names can be overridden with a +<columnOverride> configuration element.

+ +

This class will be the return value from the selectByPrimaryKey method, +or the selectByExampleWithBLOBs method.

+ +

The name of the class will be «TableName»WithBLOBs by default, or +«domainObjectName»WithBLOBs if the domainObjectName +attribute is specified on the <table> configuration element.

+ +

This class will be generated in the hierarchical model if the table has any BLOB columns. +This class will be generated in the conditional model if the table has more than one +BLOB column. This class will not be generated in the flat model.

+ +

Example Class

+

This class is used to work with MBG's dynamic select capability. +The class holds a set of criteria that are used to generate a dynamic WHERE clause at runtime +for the following methods:

+
    +
  • selectByExample
  • +
  • selectByExampleWithBLOBs
  • +
  • deleteByExample
  • +
  • countByExample
  • +
  • updateByExample
  • +
+ +

This class does not extend any of the other model classes.

+ +

The name of the class will be «TableName»Example by default, or +«domainObjectName»Example if the domainObjectName +attribute is specified on the <table> configuration element.

+ +

This class will be generated if any of the *ByExample +methods are enabled. Note that this class can grow quite large if there are many fields in a table, +but the DAO methods are small as is the generated XML fragment. +If you do not plan to use the dynamic WHERE clause features, you may prefer to +disable the generation of these methods.

+ +

See the Example Class Usage +page for details on using the example class.

+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/legacy.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/legacy.xhtml new file mode 100644 index 0000000000..370dc1dedb --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/legacy.xhtml @@ -0,0 +1,44 @@ + + + + + + Using the Legacy Generated Objects + + + +

Using the Legacy Generated Objects

+

When using one of the legacy runtimes (MyBatis3 or MyBatis3Simple), MyBatis Generator (MBG) generates these types of objects:

+
    +
  1. Java Model Objects (always)
  2. +
  3. SQL Map Files (optionally - not generated for annotated mappers)
  4. +
  5. Java MyBatis Mapper Interfaces (optional)
  6. +
  7. A class for use in the xxxByExample methods. See the following pages for + information about that class: + +
  8. +
+ +

The individual pages describe these objects, and their usage.

+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/results.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/results.xhtml new file mode 100644 index 0000000000..c3fdf6d103 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/results.xhtml @@ -0,0 +1,54 @@ + + + + + + Using the Generated Objects + + + +

Using the Generated Objects

+

MyBatis Generator (MBG) generates different types of objects depending on the runtime chosen (configured via the targetRuntime +attribute on a <context>)

+ + + + + + + + + + + + + + + + + + + + + +
RuntimeCommentsDetails
MyBatis3DynamicSqlThis is the default runtime. It is the recommended runtime for all new Java projectsDetails Page
MyBatis3KotlinThis is the recommended runtime for all Kotlin projectsDetails Page
MyBatis3 or MyBatis3SimpleThese are the original runtimes shipped with MyBatis Generator. These runtimes are in maintenance mode and will + not be enhanced.Details Page
+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/sqlmap.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/sqlmap.xhtml new file mode 100644 index 0000000000..401d179832 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/generatedobjects/sqlmap.xhtml @@ -0,0 +1,232 @@ + + + + + + MyBatis Generator Generated SQL Map XML Files + + + +

MyBatis Generator Generated SQL Map XML Files

+

Important: SQL Map XML files are not generated for the MyBatis3DynamicSQL runtime.

+ +

MyBatis Generator (MBG) generates SQL Map XML files that conform to the MyBatis SQL Map DTD. +The files contain many different +elements based on the characteristics of the table, and on the configuration options you specify. +MBG generates a different SQL Map file for every table you specify. The name space of the +SQL Map is the name of the table (qualified by schema and catalog if present). MBG does not +add the SQL Map entries to the MyBatis configuration files - you must do that manually (or you may use +a plugin to cause MBG to generate a skeleton configuration file if you wish).

+ +

Every generated XML element contains an XML comment section that contains the string @mbg.generated +. On subsequent runs, every element that contains a comment with the string +@mbg.generated +will be deleted and replaced. Any other element in the XML file will remain untouched. +With this in mind, you can add other elements to the file without fear of losing them in +subsequent runs - simply do not include the string +@mbg.generated in any element comment.

+

The following sections describe the elements that will be generated.

+ +

Note: in the following descriptions, the term "BLOB" is used to refer to any column +with a data type of BLOB, CLOB, LONGVARCHAR, or LONGVARBINARY.

+ +

Result Map

+

This element is used to map table columns to properties of the generated Java model object. +The result map (and corresponding select statements) will not contain:

+
    +
  • Any field that has been ignored by the <ignoreColumn> configuration element
  • +
  • Any BLOB field from the table (see the result map with BLOBs element)
  • +
+

The columns will be mapped according the configuration element <columnOverride> if it exists +for the specific column. If the override does not exist, then a default property name and JDBC type +will be used.

+

It is acceptable to extend this result map if you code any +custom join queries in the SQL map. This is a common use case and is expected. +If you plan to reuse this result map with other join queries, you may wish to have +MBG generate a prefix for the fields in the result map. See the +<table> reference page for information about generating +a prefix.

+

This element will be generated if either the select by example, or select by primary key statements +are enabled.

+ +

Result Map With BLOBs

+

The element extends the base result map, and adds any BLOB fields that exist in the table. +We do this because we offer different versions of the select by example statement depending on +whether or not you want to return the BLOB fields in those queries.

+ +

The result map (and corresponding select statements) will not contain:

+
    +
  • Any field that has been ignored by the <ignoreColumn> configuration element
  • +
+

The columns will be mapped according the configuration element <columnOverride> if it exists +for the specific column. If the override does not exist, then a default property name and JDBC type +will be used.

+

It is acceptable to extend this result map if you code any +custom join queries in the SQL map. This is a common use case and is expected. +If you plan to reuse this result map with other join queries, you may wish to have +MBG generate a prefix for the fields in the result map. See the +<table> reference page for information about generating +a prefix.

+

This element will be generated if that table contains BLOB fields, and either the select by example, +or select by primary key statements are enabled.

+ +

SQL Where Clause

+

This element contains a reusable where clause that is used by the "by example" methods. The +where clause will not include any BLOB fields if they exist in the table. Most databases do not +support BLOB fields in the WHERE clause.

+

This element will be generated if any of the "by example" statements +are enabled.

+ +

Select By Primary Key

+

This element contains a select statement that will return one row - designated by the primary key. +The returned row will include BLOB fields if they exist in the table.

+

This element will be generated if the table has a primary key and the select by primary key statement +is enabled.

+ +

Select by Example

+

This element contains a select statement with rows that match the example object. +This implements a simple "query by example" functionality that can be used to generate many +different database queries. The returned rows will not include any BLOB fields that exist in the table +(see the select by example with BLOBs statement below).

+

Important: If the example class is null, or no criteria have been set, +then all rows in the table will be selected.

+

This element will be generated if the select by example statement is enabled.

+ +

Select by Example With BLOBs

+

This element contains a select statement with rows that match the example object. +This implements a simple "query by example" functionality that can be used to generate many +different database queries. The returned rows will include any BLOB fields that exist in the table.

+

Important: If the example class is null, or no criteria have been set, +then all rows in the table will be selected.

+

This element will be generated if the table contains BLOB fields, and the select by example + statement is enabled.

+ +

Insert

+

This element is an insert statement that includes all fields in the table (including BLOBs), +unless the field is specifically ignored with the <ignoreColumn> configuration +element.

+

If the table has an auto generated key (an identity column or value from a sequence), and the +<generatedKey> configuration element is specified, then MBG will generate +an appropriate <selectKey> element.

+

Important Note: the method will return the number of rows inserted (typically either 0 or 1). +If a <generatedKey> element is specified, the value of the newly generated +key will be set in the corresponding property of the parameter object.

+

This element will be generated if the insert statement is enabled.

+ +

Insert Selective

+

This element is an insert statement that includes all fields in the table (including BLOBs), +unless the field is specifically ignored with the <ignoreColumn> configuration +element. However, this statement will not include fields that are null in the +parameter object. This allows you to use database defaults for columns, if they exist. +This element will not allow the insert of null into any field - for that +you must use the regular insert statement. Important: any field mapped to a Java primitive +is always inserted by this method.

+

If the table has an auto generated key (an identity column or value from a sequence), and the +<generatedKey> configuration element is specified, then MBG will generate +an appropriate <selectKey> element.

+

Important Note: the method will return the number of rows inserted (typically either 0 or 1). +If a <generatedKey> element is specified, the value of the newly generated +key will be set in the corresponding property of the parameter object.

+

This element will be generated if the insert statement is enabled.

+ +

Update By Primary Key

+

This element is an update statement that will update one row - designated by the primary +key. The update statement will update all fields in the table unless:

+
    +
  • The field has been ignored by the <ignoreColumn> configuration element
  • +
  • The field is a BLOB field (see the update by primary key with BLOBs element)
  • +
+

This element will be generated if the table has a primary key, and the update by primary +key statement is enabled.

+ +

Update By Primary Key With BLOBs

+

This element is an update statement that will update one row - designated by the primary +key. The update statement will update all fields in the table (including BLOB fields) unless:

+
    +
  • The field has been ignored by the <ignoreColumn> configuration element
  • +
+

This element will be generated if the table has a primary key, the table has BLOB columns, + and the update by primary key statement is enabled.

+ +

Update By Primary Key Selective

+

This element is an update statement that will update one row - designated by the primary +key. The update statement will update only the fields in the table whose corresponding +property in the parameter object is non-null. This statement can be used to update +certain columns in a record without affecting all columns in the record. Important: +if the column has been mapped to a primitive type, then the column will always be +updated.

+

This element will be generated if the table has a primary key, and the update by primary +key statement is enabled.

+ +

Delete By Primary Key

+

This element is a delete statement that will delete one row in the table - designated by the +primary key.

+

This element will be generated if the table has a primary key, and the delete by primary key + statement is enabled.

+ +

Delete By Example

+

This element is a delete statement that will delete one or more rows in the table - designated by +the example object.

+

Important: If the example class is null, or no criteria have been set, +then all rows in the table will be deleted.

+

This element will be generated if the delete by example statement is enabled.

+ +

Count By Example

+

This element is a select count(*) statement that will return the number of rows in the table +that match the specified example object.

+

Important: If the example class is null, or no criteria have been set, +then the select will return the number of rows in the entire table.

+

This element will be generated if the count by example statement is enabled.

+ +

Update By Example

+

This element is an update statement that will update all rows in a table that match +the specified example. The update statement will update all fields in the table unless:

+
    +
  • The field has been ignored by the <ignoreColumn> configuration element
  • +
  • The field is a BLOB field (see the update by example with BLOBs element)
  • +
+

Important: If the example class is null, or no criteria have been set, +then all rows in the table will be updated.

+

This element will be generated if the update by example statement is enabled.

+ +

Update By Example With BLOBs

+

This element is an update statement that will update all rows in a table that match +the specified example. The update statement will update all fields in the table (including BLOB fields) +unless:

+
    +
  • The field has been ignored by the <ignoreColumn> configuration element
  • +
+

Important: If the example class is null, or no criteria have been set, +then all rows in the table will be updated.

+

This element will be generated if the table contains BLOB columns, and the update by +example statement is enabled.

+ +

Update By Example Selective

+

This element is an update statement that will update all rows in a table that match the +specified example. The update statement will update only the fields in the table whose corresponding +property in the parameter object is non-null. This statement can be used to update +certain columns in certain records without affecting all columns in the records. Important: +if the column has been mapped to a primitive type, then the column will always be +updated.

+

Important: If the example class is null, or no criteria have been set, +then all rows in the table will be updated.

+

This element will be generated if the update by example statement is enabled.

+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/index.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/index.xhtml new file mode 100644 index 0000000000..23fa37826e --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/index.xhtml @@ -0,0 +1,151 @@ + + + + + + + MyBatis 生成器简介 + + + + +

MyBatis 生成器简介

+

MyBatis Generator(MBG)是 MyBatis 的代码生成器。支持 MyBatis + 的所有版本。它将内省(introspect)数据库表,并生成可用于访问表的框架(artifacts)。这减轻了在于数据库交互时需要设置对象和配置文件的负担。MBG 对大部分简单的数据库 + CRUD(创建、查询、更新、删除)操作提供支持。所以你仍然需要为连接查询或存储过程编写 SQL 和对象。 +

MBG 根据其配置方式,以不同的风格和语言生成代码。例如,MBG可以生成 Java 或 Kotlin 代码。MBG 可以生成与 MyBatis 3 兼容的 XML——尽管这现在被认为是 MBG 的传统用途。生成代码的新方式不需要 + XML。

+

根据配置方式,MyBatis 生成器可能生成:

+
    +
  • 与表结构匹配的Java或Kotlin类。这可能包括: +
      +
    • 与表的主键匹配的类(如果有主键)
    • +
    • 匹配表的非主键字段(BLOB 字段除外)的类
    • +
    • 包含表的 BLOB 字段的类(如果表有 BLOB 字段)
    • +
    • 用于启用动态查询、更新和删除的类
    • +
    +

    这些类之间有适当的继承关系。请注意,生成器可以配置以生成不同类型的 POJO 层次结构——例如,如果需要,你可以选择为每个表生成单个域对象。

    +
  • +
  • 在某些情况下,MBG 会生成与 MyBatis 3 兼容的SQL 映射 XML 文件。MBG 为配置的每个表生成简单的 CRUD 功能的 SQL。生成的 SQL 语句包括: +
      +
    • 插入
    • +
    • 根据主键更新
    • +
    • 根据示例更新(使用动态的 where 子句)
    • +
    • 根据主键删除
    • +
    • 根据示例删除(使用动态的 where 子句)
    • +
    • 根据主键查询
    • +
    • 根据示例查询(使用动态的 where 子句)
    • +
    • 根据示例计数
    • +
    +

    根据表的结构,这些语句有不同的变体(例如,如果表没有主键,则 MBG 将不会生成按主键更新的 SQL)。

    +
  • +
  • 适当使用上述对象的 Java 或 Kotlin 委托类、接口和 Kotlin 扩展方法。委托类的生成是可选的。MBG 将生成一个与 MyBatis 映射器基础设施配合使用的映射器接口。
  • +
+ +

MyBatis生成器在迭代开发环境中运行良好,并且可以作为 Ant 任务或 Maven 的插件包含在构建环境中。迭代运行 MBG 时需要注意的重要事项包括:

+ +
    +
  1. 如果存在与新生成的 XML 文件同名的现有文件,MBG 将自动合并 XML 文件。MBG 不会覆盖你对其生成的 XML 文件所做的任何自定义更改。你可以一遍又一遍地运行它,而不必担心丢失对 XML 的自定义更改。MBG + 将替换在先前运行中生成的 XML 元素。 +
  2. +
  3. MBG 不会合并 Java 文件,它可以覆盖现有文件,也可以使用不同的名称保存新生成的文件。如果对生成的 Java 文件进行更改并迭代运行 MBG ,则必须手动合并更改。当作为 Eclipse ,则 MBG 可以自动合并 Java 文件。
  4. +
  5. MBG 不会合并 Kotlin 文件,它可以覆盖现有文件,也可以使用不同的名称保存新生成的文件。如果你对生成的 Kotlin 文件进行更改并迭代运行 MBG,则必须手动合并更改。
  6. +
+ +

使用 Eclipse 运行

+

当在 Eclipse 运行时,生成器还可以合并 Java 文件,并将用户修改保存到生成的 Java 文件中。生成器使用Eclipse Java 解析器和 AST Walker 来完成此任务。Eclipse + 还具有一些用户界面增强功能,使生成器更易于运行。最后, Eclipse 提供了生成器的完整用户手册。

+

Eclipse 的这项特性可在 Eclipse 的市场上找到: + https://marketplace.eclipse.org/content/mybatis-generator。 +

+

依赖信息

+

MBG 没有 JRE 之外的依赖关系。需要Java 8 或以上版本。还需要一个 JDBC 驱动程序,其实现了 DatabaseMetaData 接口,特别是getColumns 与 + getPrimaryKeys 方法是必需的。

+ +

生成的代码依赖

+

MBG 将生成不同风格的代码。这由<context>元素的 “targetRuntime” 属性控制。所有运行时生成都会依赖于 MyBatis。一些运行时生成的代码也依赖于 MyBatis Dynamic SQL。 + 下表显示了生成的代码中所需的依赖关系。

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RuntimeMyBatis Generator VersionMyBatis VersionMyBatis Dynamic SQL Version
MyBatis3, MyBatis3SimpleAny3.0+N/A
MyBatis3DynamicSQL1.3.6 - 1.3.73.4.2+1.1.0 - 1.2.1
MyBatis3DynamicSQL, MyBatis3Kotlin1.4.03.4.2+1.1.3+
MyBatis3DynamicSQL1.4.1+3.4.2+1.3.1+
MyBatis3Kotlin1.4.1+3.4.2+1.4.0+
+ +

支持

+

通过 MyBatis 用户邮件列表提供对 MyBatis 生成器的支持。你可以 Google 代码订阅或查看邮件列表:

+ +
+

+ http://groups.google.com/group/mybatis-user +

+
+ +

如果你认为你发现了错误,请在创建新 issue 之前,先在用户列表中询问有关它的问题。如果你发现错误或有新功能请求,你可以在 GitHub 上创建新的 issue

: + +
+

+ + https://github.com/mybatis/generator/issues + +

+
+ + + + \ No newline at end of file diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/license.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/license.xhtml new file mode 100644 index 0000000000..4e04667a9b --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/license.xhtml @@ -0,0 +1,48 @@ + + + + + + Licensing Information + + + +

Licensing Information

+

Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this product except in compliance with the License. + You may obtain a copy of the License at +

+

+http://www.apache.org/licenses/LICENSE-2.0

+

+ Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +

+ +

This product includes software developed by the Apache Software +Foundation (http://www.apache.org/).

+ +

This product includes the EqualsUtil and HashCodeUtil classes +from http://www.javapractices.com.

+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/migratingFromAbator.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/migratingFromAbator.xhtml new file mode 100644 index 0000000000..82303cf24f --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/migratingFromAbator.xhtml @@ -0,0 +1,71 @@ + + + + + + 从 Abator 迁移 + + + +

从 Abator 迁移

+

此页面详细说明了 MyBatis Gernerator(MBG)和 Abator 之间的变化。对于大多数用户来说,更改应该很简单。如果你扩展 Abator 的任何类来提供自定义实现的代码生成器或 Java 类解析器,你将需要重新编写这些类。

+

这些更改分为三类:从必需的配置更改到不常见的更改。请注意,大多数更改都是假设你使用 MBG 的 XML 配置进行描述的。如果你使用的是基于 Java 的配置,那么这些更改仍然是必需的,并且应该很容易从 XML 更改的描述中推断出来。

+

所有用户都需要进行的更改

+
    +
  • DTD 已经改变了。新的 DOCTYPE 应该是: +
    +
    +<!DOCTYPE generatorConfiguration
    +  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
    +  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
    +    
    +
  • +
  • <abatorConfiguration> 元素被重命名为 + <generatorConfiguration>
  • +
  • The <abatorContext> 元素被重命名为 + <context>
  • +
  • The <daoGenerator> 元素被重命名为 + <javaClientGenerator>
  • +
+

一些用户需要更改的

+
    +
  • MyBatis3 现在是默认的目标运行环境。
  • +
  • <context> 元素现在需要一个 ID
  • +
  • generatorSet 属性已从 + <context> 元素中移除,被替换为 + targetRuntime 属性。此属性的有效值为 MyBatis3MyBatis3Simple 或者 MyBatis3DynamicSql
  • +
  • MBG 的类加载策略已经发生了实质性的变化,现在我们建议您管理 MBG 外部的运行时类路径。如果使用配置管理类路径,则必须从 Abator 中进行以下更改: +
      +
    • 类路径条目在配置文件级别指定,使用 <classPathEntry> 元素,现在仅仅是 <generatorConfiguration> 的子元素<。/li> +
    • <classPathEntry> 不再允许作为 <jdbcConnection> 的子元素。
    • +
    • "rootClasspath" 属性不再是 <javaModelGenerator> 元素的合法值。
    • +
    +
  • +
+

很少人需要的更改

+
    +
  • type 属性将从 + <javaModelGenerator> 和 + <sqlMapGenerator> 元素中移除。MBG 提供自定义代码生成器的方法与 Abator 完全不同。参见 从 MyBatis Generator 中扩展以获取更多信息。
  • +
  • JavaTypeResolver 接口已更改并简化。如果你在 <javaTypeResolver> 元素上指定了自定义实现。你必须重新编写你的实现类。
  • +
  • ProgressCallback 接口已经发生了显著的变化。如果你为其他执行环境实现了此接口,则需要重新编写你的实现。
  • +
+ + \ No newline at end of file diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/migratingFromIbator.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/migratingFromIbator.xhtml new file mode 100644 index 0000000000..06434c3f8a --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/migratingFromIbator.xhtml @@ -0,0 +1,52 @@ + + + + + + 从 Ibator 迁移 + + + +

从 Ibator 迁移

+

这个页面详细介绍了 MyBatis Generator(MBG)和 Ibator 的变化。对于大多数用户来说,更改应该很简单。如果你扩展了任何 Ibator 的类,以提供代码生成器或 Java 类解析器的自定义实现,你将需要重新编写这些自定义类。

+

假设你正在使用 MBG 的 XML 配置,将描述它的更改。如果你使用的是基于 Java 的配置,那么这些更改仍然是必需的,并且应该很容易从 XML 更改的描述中推断出来。

+

部分用户需要的更改

+
    +
  • DTD 已经发生了变化,新的 DOCTYPE 应该是: +
    +
    +<!DOCTYPE generatorConfiguration
    +  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
    +  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
    +    
    +
  • +
  • MyBatis3 现在是默认的目标运行环境。
  • +
  • <ibatorConfiguration> h + <generatorConfiguration>
  • +
  • <ibatorContext> 元素被重命名为 + <context>
  • +
  • <ibatorPlugin> 元素被重命名为 + <plugin>
  • +
  • <daoGenerator> 元素被重命名为 + <javaClientGenerator>
  • +
  • 如果你实现了插件,则 daoXXX 方法已经被重命名为 clientXXX
  • +
+ + \ No newline at end of file diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/philosophy.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/philosophy.xhtml new file mode 100644 index 0000000000..12220db44c --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/philosophy.xhtml @@ -0,0 +1,67 @@ + + + + + + Philosophy and Apology + + + +

Philosophy and Apology

+

这个工具可能会提出一些哲学问题,因为这个工具更关注数据库表,而不是领域模型。我们将通过几个段落来谈谈这种方法。

+ +

首先,这个工具做了它该做的。我们并没有就项目如何组织发表任何看法。总的来说,我们是富领域模型的坚定支持者——但创建一个富领域模型与回答如何坚持该模型的问题是完全不同的。

+ +

如果你的设计理念是由域模型驱动来所有决策,并且数据库设计服从于域模型,那么此工具——以及 MyBatis 本身——可能不适合你的应用程序。在这种情况下,我们建议认真研究 Hibernate——它可能更符合您的应用设计和理念。

+ +

但并不是所有的项目都符合这种范式。很少有真正的企业级应用程序能做到。在数据库设计被视为与领域对象设计等同的项目中, MyBatis 可能会有很大的帮助。MyBatis 不是对象关系映射器,也不尝试透明地持久化对象。因此,编写 SQL 来与数据库表交互就是应用程序开发人员的事情了。

+ +

在大型或企业级项目中,这些因素中的许多是相当常见的:

+
    +
  • 在面向对象的域模型设计中,数据库设计通常是一个单独的功能,有着自己的管理模式。 +
  • +
  • 数据库设计者没有面向对象的工具(比如继承),所以他们不会用面向对象的术语来思考。
  • +
  • 应用程序设计人员不能完全控制数据库表的最终形式。例如,似乎适合应用程序的一个对象的数据可能会被拆分为数据库中的几个表。
  • +
  • 数据库设计最终往往与面向对象的设计大不相同,导致表和对象之间的不匹配。
  • +
+

+这些因素是 MyBatis 对你的应用程序来说是一个很好的候选工具的主要指标,这也是 MyBatis Generator 可以产生重大影响的项目类型。那么,在这种情况下,应该如何使用 MyBatis 呢?

+ +

数据访问对象(DAO)模式仍然是一种主要模式。MyBatis Generator 可以生成与每个单独表匹配的基本对象集合。生成的代码是事务中立的。这意味着,如果一个事务涉及多个表,则很容易扩展生成的代码以添加事务属性。或者,您可以创建另一个 DAO(或 service 方法),它更符合域对象的持久化需求,并在单个事务中使用一个或多个生成的对象。

+ +

例如,考虑一个典型的 Order 对象——典型的 header/detail 问题。 +在某些环境中,这样的对象将被持久化到至少 4 个表中——两个关键表、一个“表头”表和一个“详细信息”表(同样,我们并没有就这是否“正确”的设计发表任何看法,只是陈述一个事实). +您的应用程序仍应与 Order 对象交互,可能会有一个 saveOrder(Order order) 方法在某个地方(在 OrderDAO 或 service 对象中)。该方法将与所涉及的 4 个表中的每一个表的生成代码交互。

+ +

在这种情况下,代码生成给我们带来了什么?如下:

+
    +
  • 重用——可能需要从多个不同的 DAO 或 Service 方法访问某些表。为每个表创建 DAO 可促进应用程序内的重用和一致性。
  • +
  • 数据库抽象——Service 层通常定义应用程序中的持久性。这些方法可以相当快地确定下来。随着数据库设计的发展: +
      +
    1. 代码可以随着表的变化快速重新生成
    2. +
    3. Service 方法可以根据需要进行修改
    4. +
    5. 应用程序中的高层可以保持不变
    6. +
    +
  • +
  • 开发人员的生产力——生成基于表的 DAO 是快速、可重复和无错误的。开发人员可以专注于对象持久性,如果需要,还可以专注于复杂的连接查询。
  • +
  • 更少的缺陷——因为任何应用程序中最乏味和最容易出错的部分(让 SQL 与对象匹配)都是自动化的。
  • +
+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/quickstart.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/quickstart.xhtml new file mode 100644 index 0000000000..f0bbc09702 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/quickstart.xhtml @@ -0,0 +1,194 @@ + + + + + + MyBatis Generator 快速入门指南 + + + +

MyBatis Generator 快速入门指南

+

MyBatis Generator(MBG)根据其配置方式生成不同样式的代码。这可以通过在<context>配置元素上指定 targetRuntime 属性来控制。下表总结了不同的选项。

+ +

要使用 MyBatis 生成器(MBG)快速启动并运行,请执行以下步骤:

+
    +
  1. 适当地创建并填写配置文件(有关示例,请参见下文)
  2. +
  3. 将文件保存在一些适当的位置(如 \temp\generatorConfig.xml)
  4. +
  5. 使用以下命令从命令行运行 MBG: +
    +
    +      java -jar mybatis-generator-core-x.x.x.jar -configfile \temp\generatorConfig.xml -overwrite
    +    
    +

    这将使 MBG 使用配置文件运行。它还将使 MBG 覆盖任何具有相同名称的现有 Java 或 Kotlin 文件。如果要保存任何现有文件,请省略 -overwrite 参数。如果存在冲突,MBG 将使用唯一名称保存新生成的文件(例如 MyClass.java.1)。

    +
  6. +
  7. 运行 MBG 后,您需要使用新生成的代码创建或修改标准 MyBatis 配置。请参见运行 MyBatis Generator 以后页面
  8. +
+ +

目标运行环境信息和示例

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
目标运行环境注释配置示例
MyBatis3DynamicSql这是默认值 +
    +
  • 生成 Java 代码
  • +
  • 不生成 XML——使用 MyBatis 3 注解
  • +
  • 生成的模型对象是“平面”的——没有单独的主键对象
  • +
  • 生成的代码依赖于 MyBatis 动态 SQL 库
  • +
  • 生成的代码量相对较少
  • +
  • 生成的代码在查询结构中具有巨大的灵活性
  • +
+
配置示例
MyBatis3Kotlin +
    +
  • 生成 Kotlin 代码
  • +
  • 不生成 XML——使用 MyBatis 3 注解
  • +
  • 生成的模型对象是“平面”的——没有单独的主键对象
  • +
  • 生成的代码依赖于 MyBatis 动态 SQL 库
  • +
  • 生成的代码量相对较少
  • +
  • 生成的代码在查询结构中具有巨大的灵活性
  • +
+
配置示例
MyBatis3这是原始的运行环境。在 MBG 1.3.6 版本之前,MBG 的大多数用法都使用了这种风格的代码。 +
    +
  • 生成 Java 代码
  • +
  • 生成 MyBatis3 兼容的 XML 和 SQL 或 MyBatis3 兼容的注解接口,而不使用 XML
  • +
  • 生成的模型对象可以具有单独主键对象,具有 BLOB 字段的单独对象的层次结构
  • +
  • 生成的代码没有外部依赖关系
  • +
  • 生成的代码量非常大
  • +
  • 生成的代码对于查询结构的能力有限,难以扩展
  • +
+
配置示例
MyBatis3Simple这是 MyBatis3 运行环境的简化版本。 +
    +
  • 生成 Java 代码
  • +
  • 生成 MyBatis 3 兼容的 XML 和 SQL 或 MyBatis 3 兼容的注解接口,而不使用 XML
  • +
  • 生成的模型对象是“平面”的——没有单独的主键对象
  • +
  • 生成的代码没有外部依赖关系
  • +
  • The amount of generated code is relatively small
  • +
  • No "by example" or "selective" methods are generated
  • +
  • The generated code does not include methods for dynamic query construction and is difficult to extend
  • +
+
Sample Configuration
+ + +

Sample Configuration for MyBatis3DynamicSql

+
+<!DOCTYPE generatorConfiguration PUBLIC
+ "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
+ "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
+<generatorConfiguration>
+  <context id="dsql" targetRuntime="MyBatis3DynamicSql">
+    <jdbcConnection driverClass="org.hsqldb.jdbcDriver"
+        connectionURL="jdbc:hsqldb:mem:aname" />
+
+    <javaModelGenerator targetPackage="example.model" targetProject="src/main/java"/>
+
+    <javaClientGenerator targetPackage="example.mapper" targetProject="src/main/java"/>
+
+    <table tableName="FooTable" />
+  </context>
+</generatorConfiguration>
+
+ +
+

Sample Configuration for MyBatis3Kotlin

+
+<!DOCTYPE generatorConfiguration PUBLIC
+ "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
+ "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
+<generatorConfiguration>
+  <context id="kotlin" targetRuntime="MyBatis3Kotlin">
+    <jdbcConnection driverClass="org.hsqldb.jdbcDriver"
+        connectionURL="jdbc:hsqldb:mem:aname" />
+
+    <javaModelGenerator targetPackage="example.model" targetProject="src/main/kotlin"/>
+
+    <javaClientGenerator targetPackage="example.mapper" targetProject="src/main/kotlin"/>
+
+    <table tableName="FooTable" />
+  </context>
+</generatorConfiguration>
+
+ +
+

Sample Configuration for MyBatis3

+
+<!DOCTYPE generatorConfiguration PUBLIC
+ "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
+ "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
+<generatorConfiguration>
+  <context id="simple" targetRuntime="MyBatis3">
+    <jdbcConnection driverClass="org.hsqldb.jdbcDriver"
+        connectionURL="jdbc:hsqldb:mem:aname" />
+
+    <javaModelGenerator targetPackage="example.model" targetProject="src/main/java"/>
+
+    <sqlMapGenerator targetPackage="example.mapper" targetProject="src/main/resources"/>
+
+    <javaClientGenerator type="XMLMAPPER" targetPackage="example.mapper" targetProject="src/main/java"/>
+
+    <table tableName="FooTable" />
+  </context>
+</generatorConfiguration>
+
+ +
+

Sample Configuration for MyBatis3Simple

+
+<!DOCTYPE generatorConfiguration PUBLIC
+ "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
+ "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
+<generatorConfiguration>
+  <context id="simple" targetRuntime="MyBatis3Simple">
+    <jdbcConnection driverClass="org.hsqldb.jdbcDriver"
+        connectionURL="jdbc:hsqldb:mem:aname" />
+
+    <javaModelGenerator targetPackage="example.model" targetProject="src/main/java"/>
+
+    <javaClientGenerator type="ANNOTATEDMAPPER" targetPackage="example.mapper" targetProject="src/main/java"/>
+
+    <table tableName="FooTable" />
+  </context>
+</generatorConfiguration>
+
+ + + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/reference/building.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/reference/building.xhtml new file mode 100644 index 0000000000..b2f59eb58d --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/reference/building.xhtml @@ -0,0 +1,60 @@ + + + + + + Building from Source + + + +

Building from Source

+

All MyBatis Generator (MBG) distributions include source code. +It is straight forward to compile MBG from source - simply unzip the source in +a distribution and compile it with your favorite tool.

+

The MBG distribution does not contain the tests that are run during the build, +or other classes that are a necessary part of the build. If you would like to +inspect those classes, or build MBG from the very latest version of the source code +at GitHub then follow these steps:

+
    +
  1. MBG is built with Apache Maven. First you must get maven + running. If you are new to Maven, here are the most simple steps (for Windows): +
      +
    1. Download a Maven distribution from + http://maven.apache.org/
    2. +
    3. Unzip the distribution somewhere convenient
    4. +
    5. Setup environment variables and the PATH. Examples:
      + set JAVA_HOME=C:\Program Files\java\jdk1.8.0_91
      + set M2_HOME=C:\JavaTools\apache-maven-3.3.9
      + set PATH=%PATH%;%M2_HOME%\bin; +
    6. +
    +
  2. +
  3. Clone or fork the official Git repo on GitHub + + https://github.com/mybatis/generator +
  4. +
  5. Open a command window in the directory where you checked out the source
  6. +
  7. cd core
  8. +
  9. Run the command mvn clean install - or any of the other Maven lifecycle commands.
  10. +
+ + + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/reference/extending.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/reference/extending.xhtml new file mode 100644 index 0000000000..2e5b9b920b --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/reference/extending.xhtml @@ -0,0 +1,162 @@ + + + + + + Extending MyBatis Generator + + + +

Extending MyBatis Generator

+

MyBatis Generator (MBG) is designed for extensibility. All code generation is performed using a +simple DOM representation of Java and XML elements.

+

The Java DOM is included in the package org.mybatis.generator.api.dom.java

+

The XML DOM is included in the package org.mybatis.generator.api.dom.xml

+

These classes are not sufficient for every conceivable code generation possibility, but they are quite +useful for generating simple to moderately complex Java and XML code.

+ +

Using options in the configuration file, you can provide your own implementations +of many of the key code generation interfaces. You can also subclass any of the provided implementations +to provide customized behaviors. This page will describe the public APIs available +and provide pointers to the source code for further investigation. If you have +any difficulty understanding how to extend MBG, feel free to send a note to the +support mailing list at +mybatis-user@googlegroups.com.

+ +

Extending Versus Plugging In

+

Although there are a number of different extension points shown on this +page, in most cases it will be far easier to extend MBG through the use of a plugin. See the +Implementing Plugins reference page for more information.

+

The primary extension point for code generation is +org.mybatis.generator.api.IntrospectedTable. Implementing a code generator +is a non-trivial task and should only be contemplated when you want to completely replace +the code generation activities of MBG. In the years since the original release of Abator, +very few enhancement requests have appeared that could not be handled by a plugin.

+ +

Extension Points

+

MBG provides a number of different extension points. The following sections +list the different methods of extending MBG, and describe the types of +activities that can be accomplished with the different extensions. If you +need some help understanding the different options, feel free to ask a question +on the user mailing list.

+ +

org.mybatis.generator.api.IntrospectedTable

+

IntrospectedTable is an abstract class that can be extended to supply +different code generators than the versions supplied with MBG. A good example of +such an implementation would be a FreeMarker or Velocity template based +implementation. In most other instances, coding a plugin is the better way to go.

+

If you choose to extend this class, you must supply code to generate Java and XML +files. You may choose to generated those files with the +technology of your choice. The base IntrospectedTable class holds an instance +of org.mybatis.generator.internal.rules.Rules that can be queried +to determine many of the rules for code generation.

+

MBG supplies several implementations of introspected table. The implementation is chosen +based on the value of the targetRuntime attribute of the +<context> element. In many cases it will be far simpler +to extend one of the built in implementations, rather than creating an implementation +from scratch. The following table shows the built in implementations:

+ + + + + + + + + +
TargetRuntimeImplementation
MyBatis3 (default)org.mybatis.generator.codegen.mybatis3.IntrospectedTableMyBatis3Impl
+ +

If you choose to implement this extension point, specify the fully qualified +class name of your implementation with the targetRuntime +attribute of the <context> element.

+ +

org.mybatis.generator.api.IntrospectedColumn

+

IntrospectedColumn is a class that holds information about a +column as it is returned from database metadata. In some rare +circumstances it might be desirable to override this class to provide +your own implementation - especially if you create a new set of code +generators.

+

If you choose to implement this extension point, specify the fully qualified +class name of your implementation with the introspectedColumnImpl +attribute of the <context> element.

+ +

org.mybatis.generator.api.JavaTypeResolver

+

MBG calls methods in this interface to map JDBC types to Java types + during database introspection. The default implementation of this + interface is org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl. + You can provide your own implementation, and the default implementation has + been designed for extensibility.

+ +

To provide your own implementation, specify the fully qualified class name + in the XML configuration like this:

+
+    <javaTypeResolver type="mypackage.MyImplementation">
+      ...
+    </javaTypeResolver>
+
+ +

org.mybatis.generator.api.ShellCallback

+

MBG calls methods in this interface to perform functions that it cannot + do on its own. The most important of these functions are:

+
    +
  • Translating project/package into a directory structure
  • +
  • Merging Java source files in the event that an existing Java file of + the same name/package exists.
  • +
+ +

The default implementation of this interface is + org.mybatis.generator.internal.DefaultShellCallback. The default + implementation simply concatenates project and package together and creates + the necessary package directories if needed. The default implementation does not + support merging of Java files, and will either overwrite or ignore files.

+ +

You can provide your own implementation. This would be the most important + class to write if you want to integrate MBG into some other environment. + For example, the Eclipse plugin provides an implementation of this interface that + supports Java file merging when running in the Eclipse environment.

+ +

To provide your own implementation, supply an instance of the interface + on the constructor to the org.mybatis.generator.api.MyBatisGenerator + object. This cannot be configured through XML. If you are providing + your own implementation of this interface then we assume that you are + also providing some collateral code (like a new Ant task) to run + your implementation.

+ +

org.mybatis.generator.api.ProgressCallback

+

MBG calls methods in this interface to report progress during the + generation of files (a long running process). The default implementation + of this interface is + org.mybatis.generator.internal.NullProgressCallback + which simply ignores all progress messages. You can provide an + implementation of this interface to support progress notifications and + cancellation of code generation.

+ +

Implementing this interface would be important when integrating MBG + into other IDE environments. The Eclipse plugin provides an implementation + of this interface that hooks into Eclipse's progress notification system.

+ +

To provide your own implementation, supply an instance of the interface + on one of the org.mybatis.generator.api.MyBatisGenerator.generate() method calls. + This cannot be configured through XML. Again, we assume that if you are providing + your own implementation of this interface then you are + also providing some collateral code (like a new Ant task or an IDE integration) to run + your implementation.

+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/reference/intro.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/reference/intro.xhtml new file mode 100644 index 0000000000..367a9a6475 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/reference/intro.xhtml @@ -0,0 +1,38 @@ + + + + + + Reference Information + + + +

Reference Information

+

This section collects useful information related to technical topics +with MyBatis Generator.

+ + + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/reference/logging.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/reference/logging.xhtml new file mode 100644 index 0000000000..61a6604025 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/reference/logging.xhtml @@ -0,0 +1,154 @@ + + + + + + Logging Information + + + +

Logging Information

+

MyBatis Generator (MBG) reports logging information in several different ways:

+
    +
  • MBG may generate and display warning messages every time it is run. These + messages are meant to inform the user of significant events that may, or may not, + require attention. Examples are files being overwritten, non-fatal configuration errors, etc. + Warnings are always displayed - regardless of configuration or command line options.
  • +
  • MBG generates and may, or may not, display progress messages every time it is run. + These messages are meant to inform to user of progress in code generation. These messages + are not displayed by default, but may be enabled by specifying the -verbose + command line argument. Or, if you are running MBG with the built in Ant task, these + messages may be enabled by setting the verbose attribute to true, + and then running Ant in verbose mode.
  • +
  • Lastly, MBG will generate tracing (logging) messages for detailed debugging. + This page explains how to enable these statements.
  • +
+ +

In general, MBG will not repeat messages. So if MBG generates a warning, +that warning is typically not also logged. In some situations it may be useful +to enable logging as well as asking MBG to be verbose with progress messages. +This may generate a substantial output, but it will also give a very complete +picture of what's happening internally during the MBG run.

+ +

By default, MBG will use SLF4J logging if it is on the runtime classpath. +See https://www.slf4j.org/ +for more information about SLF4J. If SLF4J is not in the runtime classpath, +MBG will search for logging implementations in the following order:

+
    +
  1. SLF4J
  2. +
  3. Jakarta Commons Logging
  4. +
  5. Log4J V2
  6. +
  7. JDK Standard logging
  8. +
+

If for any reason you prefer to force the use of JDK standard logging, even +if other implementations are on the runtime classpath, you may specify the command line +options -forceJavaLogging.

+

If you are running MBG from Java, you can also call one of the following methods to force a particular logging +implementation:

+
    +
  • org.mybatis.generator.logging.LogFactory.forceJavaLogging();
  • +
  • org.mybatis.generator.logging.LogFactory.forceSlf4jLogging();
  • +
  • org.mybatis.generator.logging.LogFactory.forceCommonsLogging();
  • +
  • org.mybatis.generator.logging.LogFactory.forceLog4j2Logging();
  • +
  • org.mybatis.generator.logging.LogFactory.forceNoLogging();
  • +
+ +

Important: You should call these methods before any other MBG code.

+ +

Supplying an Alternate Implementation

+

If you prefer to use a different logging implementation than one of the build in implementations, +you may supply an alternate implementation of the key logging +interfaces as follows:

+
    +
  1. Create an implementation of the org.mybatis.generator.logging.Log + interface that implements the key logging methods for you logging implementation + of choice.
  2. +
  3. Create an implementation of the org.mybatis.generator.logging.AbstractLogFactory + interface that will return instances of your Log implementation.
  4. +
  5. Configure MBG to use your new LogFactory by calling the method + org.mybatis.generator.logging.LogFactory.setLogFactory(AbstractLogFactory) + and supplying an instance of your AbstractLogFactory implementation.
  6. +
+ +

Configuring SLF4J Logging

+

The following is a sample Logback configuration file (Logback is the default implementation of SLF4J):

+
+<configuration>
+  <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
+    <encoder>
+      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+    </encoder>
+  </appender>
+  <logger name="org.mybatis.generator" level="debug" />
+  <root level="error">
+    <appender-ref ref="Console" />
+  </root>
+</configuration>
+
+ +

This file will instruct SLF4J to write all MBG debug messages +to the console. To use this file:

+
    +
  1. Create a file called logback.xml in the + root of your runtime classpath
  2. +
  3. Copy the above entries into the new file
  4. +
  5. Run MBG with Logback classic as a dependency in your POM.
  6. +
+

You should see many log messages in the console.

+

You may also configure SLF4J in any of the other supported +methods if you prefer.

+ +

Configuring Java Logging

+

The following is a sample Java logging configuration file:

+
+# Specify the handlers to create in the root logger
+# (all loggers are children of the root logger)
+handlers = java.util.logging.ConsoleHandler
+
+# Set the default logging level for the root logger
+.level = INFO
+
+# Set the default logging level for new ConsoleHandler instances
+java.util.logging.ConsoleHandler.level = ALL
+
+# Set the default formatter for new ConsoleHandler instances
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+# Set the default logging level for the logger named org.mybatis.generator
+org.mybatis.generator.level = FINE
+
+

This file will instruct Java to write all MBG debug messages +to the console. To use this file:

+
    +
  1. Create a file called logging.properties (or any + file name you prefer). The file can exist anywhere in + the file system (for example, in a \temp directory).
  2. +
  3. Copy the above entries into the new file
  4. +
  5. Run MBG with this VM argument:
    + -Djava.util.logging.config.file=\temp\logging.properties + (specify whatever actual file name and directory you used) +
  6. +
+

You should see many log messages in the console.

+

You may also configure Java logging in any of the other supported +methods if you prefer.

+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/reference/pluggingIn.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/reference/pluggingIn.xhtml new file mode 100644 index 0000000000..ed6419f38c --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/reference/pluggingIn.xhtml @@ -0,0 +1,130 @@ + + + + + + Implementing Plugins + + + +

Implementing Plugins

+

Plugins can be used to modify or add to the objects that are generated by MyBatis Generator. +Plugins must implement the interface +org.mybatis.generator.api.Plugin. The plugin interface contains many +methods that are called in different phases of the code generation process. Implementing the +entire interface is generally not needed for any particular plugin. Therefore, most plugins should extend +the adapter class org.mybatis.generator.api.PluginAdapter. The adapter +class provides basic plugin support, and implements no-operation methods for most of the +interface methods (similar to Swing adapter classes).

+ +

MyBatis Generator supplies several plugins (all are in the package +org.mybatis.generator.plugins). The supplied plugins demonstrate +different types of tasks that can be accomplished with plugins. Source +code for the plugins is available with the downloads, or can be viewed +online + +here.

+ +

Plugin Lifecycle

+

Plugins have a lifecycle. Plugins are created during the initialization of the code +generation process and are called, in order, in different phases of the process. The following +list shows the basic lifecycle of a plugin:

+
    +
  1. Plugin created through the default constructor
  2. +
  3. setContext method called
  4. +
  5. setProperties method called
  6. +
  7. validate method called. If this method returns false, + then no further methods in the plugin will be called
  8. +
  9. For each table in the configuration: +
      +
    1. initialized method called
    2. +
    3. Java Client Methods:1,2 +
        +
      1. clientXXXMethodGenerated(Method, TopLevelClass, IntrospectedTable) - these methods + are called as each method of a Java client implementation class is generated.
      2. +
      3. clientXXXMethodGenerated(Method, Interface, IntrospectedTable) - these methods + are called as each method of the Java client interface is generated.
      4. +
      5. clientGenerated(Interface, TopLevelClass, IntrospectedTable) method called
      6. +
      +
    4. +
    5. Model Methods:1 +
        +
      1. modelFieldGenerated, modelGetterMethodGenerated, + modelSetterMethodGenerated for each field in the class
      2. +
      3. modelExampleClassGenerated(TopLevelClass, IntrospectedTable)
      4. +
      5. modelPrimaryKeyClassGenerated(TopLevelClass, IntrospectedTable)
      6. +
      7. modelBaseRecordClassGenerated(TopLevelClass, IntrospectedTable)
      8. +
      9. modelRecordWithBLOBsClassGenerated(TopLevelClass, IntrospectedTable)
      10. +
      +
    6. +
    7. SQL Map Methods:1 +
        +
      1. sqlMapXXXElementGenerated(XmlElement, IntrospectedTable) - these methods + are called as each element of the SQL map is generated
      2. +
      3. sqlMapDocumentGenerated(Document, IntrospectedTable)
      4. +
      5. sqlMapDocument(GeneratedXmlFile, IntrospectedTable)
      6. +
      +
    8. +
    9. contextGenerateAdditionalJavaFiles(IntrospectedTable) method called
    10. +
    11. contextGenerateAdditionalXmlFiles(IntrospectedTable) method called
    12. +
    +
  10. +
  11. contextGenerateAdditionalJavaFiles() method called
  12. +
  13. contextGenerateAdditionalXmlFiles() method called
  14. +
+ +

Notes:
+1 - These methods will be called by the packaged code generators. If you supply + a custom code generator, then these methods will only be called if the custom code generator + calls them.
+2 - The Java client methods will only be called is a Java client generator is configured. +

+ +

Coding Plugins

+

The best way to implement a plugin is to extend the +org.mybatis.generator.api.PluginAdapter class and override +only the specific methods you need in your plugin.

+

Methods in the plugin interface can be used to modify code generated by default, or +to add additional generated code. Examples of things that can be accomplished with +plugins are:

+
    +
  • Add custom annotations to generated methods
  • +
  • Add additional methods to a generated class
  • +
  • Add additional elements to a generated XML file
  • +
  • Generate additional Java files
  • +
  • Generate additional XML files
  • +
+ +

The contextXXX methods will always be called. Other methods are called +by the packaged code generators - and only if the rules for a table would +cause the generation of a particular element. For example, the +modelPrimaryKeyClassGenerated(TopLevelClass, IntrospectedTable) +method will not be called if the table does not have a primary key.

+ +

Methods that return a boolean can be used to bypass code generation. +If any of these methods return false, then the related item will +not be added to the generated code. If there is more than one plugin configured, +then the first plugin to return false from a method will cause MyBatis Generator to stop calling +that method in all other plugins.

+ +

If you have an idea for a plugin, feel free to ask a question about it on +the user list. We're here to help!

+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/reference/plugins.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/reference/plugins.xhtml new file mode 100644 index 0000000000..0b4076f066 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/reference/plugins.xhtml @@ -0,0 +1,226 @@ + + + + + + Supplied Plugins + + + +

Supplied Plugins

+

As usage of MyBatis Generator (MBG) grows, we find it increasingly +useful to add capabilities through plugins, rather than adding to the complexity +of the base code generators. Plugins are a modular and easily understood mechanism +for extending MBG. For more information on writing a plugin, see +Implementing Plugins. For information on +configuring plugins, see <plugin>

+ +

Most of the supplied plugins are in the package +org.mybatis.generator.plugins. The supplied plugins demonstrate +different types of tasks that can be accomplished with MBG plugins. Source +code for the plugins is available with the MBG downloads, or can be viewed +online + +here.

+ +

org.mybatis.generator.plugins.CacheNamespacePlugin

+

This plugin adds a @CacheNamespace annotation to generated mapper interface (Kotlin or Java). This + plugin is for MyBatis3 targeted runtimes only.

+

This plugin accepts the following properties. All are optional and, + if specified, most values (except "cache_skip") will be passed directly to the corresponding property + on the generated @CacheNamespace annotation. The cache_eviction and cache_implementation properties + must be fully qualified class names. The class will be added to the import list in the mapper, and the + short name will be used on the generated annotation. + If "cache_skip" is set to "true" on the plugin configuration, + or for any table, the annotation will not be generated.

+
    +
  • cache_blocking
  • +
  • cache_flushInterval
  • +
  • cache_readWrite
  • +
  • cache_size
  • +
  • cache_eviction (must be a fully qualified class name)
  • +
  • cache_implementation (must be a fully qualified class name)
  • +
  • cache_skip
  • +
+

Any property can be overridden by specifying the property on a <table> element.

+ +

org.mybatis.generator.plugins.CachePlugin

+

This plugin has no impact when the target runtime in use does not generate XML.

+

This plugin adds a <cache> element to generated SQL maps.

+

This plugin accepts the following properties. All are optional and, +if specified, the values will be passed directly to the corresponding property +on the generated <cache> element.

+
    +
  • cache_eviction
  • +
  • cache_flushInterval
  • +
  • cache_readOnly
  • +
  • cache_size
  • +
  • cache_type
  • +
+

Any property can be overridden by specifying the property on a <table> +element.

+ +

org.mybatis.generator.plugins.CaseInsensitiveLikePlugin

+

This plugin has no impact when the target runtime in use is based on MyBatis Dynamic SQL.

+

This plugin adds methods to the Example class (actually to the Criteria inner class) +to support case insensitive LIKE searches. This demonstrates adding functionality to +the example classes via a plugin, rather than extending the class.

+ +

org.mybatis.generator.plugins.EqualsHashCodePlugin

+

This plugin has no impact and is not needed when the target runtime in use is MyBatis3Kotlin.

+

This plugin adds equals and hashCode methods to the +Java model objects generated by MBG.

+

By default, the equals and hashCode method checks the only fields it knows +about generated by this class.

+ +

This plugin accepts one property:

+
    +
  • useEqualsHashCodeFromRoot (optional) If you have specified root class, you can use + this property to call super equals and hashCode methods for check + fields of root class. It can be useful for tables with inheritance relation.
  • +
+ +

org.mybatis.generator.plugins.FluentBuilderMethodsPlugin

+

This plugin has no impact and is not needed when the target runtime in use is MyBatis3Kotlin.

+

This plugin adds fluent builder methods to the generated model classes.

+ +Example: +
    +
  • given the domain class MyDomainClass
  • +
  • with setter-method setFoo(String foo)
  • +
  • with setter-method setBar(Integer bar)
  • +
+ +The plugin will create the additional Methods: +
    +
  • public MyDomainClass withFoo(String foo)
  • +
  • public MyDomainClass withBar(Integer bar)
  • +
+ +

This plugin does not accept any properties.

+ +

Using this plugin, you can configure the property values fluently with chained method calls. Example: new MyDomain().withFoo("Test").withBar(4711);

+ + +

org.mybatis.generator.plugins.MapperAnnotationPlugin

+

This plugin has no impact and is not needed when the target runtime in use is based on MyBatis Dynamic SQL.

+

This plugin adds the @Mapper annotation to generated mapper interfaces. This +plugin should only be used in MyBatis3 environments.

+ +

org.mybatis.generator.plugins.MapperConfigPlugin

+

This plugin has no impact and is not needed when the target runtime in use is based on MyBatis Dynamic SQL.

+

This plugin generates a skeleton MapperConfig.xml file that contains +references to the XML mapper files generated by MBG. +This file can be used to configure MyBatis 3.x environments.

+

This plugin accepts three properties:

+
    +
  • fileName (optional) the name of the generated file. + this defaults to "MapperConfig.xml" if not specified.
  • +
  • targetPackage (required) the name of the package where the + file should be placed. Specified like "com.mycompany.sql".
  • +
  • targetProject (required) the name of the project where the + file should be placed.
  • +
+

Note: targetPackage and targetProject follow + the same rules as the targetPackage and targetProject + values on the sqlMapGenerator configuration element.

+ +

org.mybatis.generator.plugins.RenameExampleClassPlugin

+

This plugin has no impact and is not needed when the target runtime in use is based on MyBatis Dynamic SQL.

+

This plugin demonstrates usage of the initialized method +by renaming the generated example classes generated by MBG.

+

This plugin accepts two properties:

+
    +
  • searchString (required) a regular expression used to search + the default generated name of the example class.
  • +
  • replaceString (required) the string to be inserted on matches of the + searchString.
  • +
+

For example, to rename the generated example classes from xxxExample to + xxxCriteria, specify Example$ for searchString + and Criteria for replaceString

+ +

org.mybatis.generator.plugins.RowBoundsPlugin

+

This plugin has no impact and is not needed when the target runtime in use is based on MyBatis Dynamic SQL.

+

This plugin will add a new version of the selectByExample +method that accepts a RowBounds parameter. This supports the +MyBatis RowBounds function where a returned result list can be limited +in length, and a start position can be specified. This can be useful +in paging applications.

+

This plugin is only valid for MyBatis3 target runtime.

+ +

org.mybatis.generator.plugins.SerializablePlugin

+

This plugin adds the marker interface java.io.Serializable to the +Java model classes, and/or the Kotlin data classes, generated by MBG. For Java, this plugin also adds the +serialVersionUID field to the model classes.

+

Important: This is a simplistic implementation of java.io.Serializable and does +not attempt to do any versioning of classes.

+

This plugin accepts two properties. Note that both properties are ignored for Kotlin data classes. For +Kotlin data classes, the plugin will always and only add java.io.Serializable.

+
    +
  • addGWTInterface (optional) True/False. If true, the plugin will add + the Google Web Toolkit (GWT) IsSerializable interface to the model + objects. The default is false.
  • +
  • suppressJavaInterface (required) True/False. If true, the plugin will + NOT add the java.io.Serializable interface. This is for the case where + the objects should be serializable for GWT, but not in the strict Java sense. The + default is false.
  • +
+ +

org.mybatis.generator.plugins.ToStringPlugin

+

This plugin has no impact and is not needed when the target runtime in use is MyBatis3Kotlin.

+

This plugin adds toString() methods to the generated +model classes.

+ +

This plugin accepts one property:

+
    +
  • useToStringFromRoot (optional) If you have specified root class, you can use + this property to call super toString method for print + fields of root class. It can be useful for tables with inheritance relation.
  • +
+ +

org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin

+

This plugin has no impact and is not needed when the target runtime in use is based on MyBatis Dynamic SQL.

+

This plugin will disable the XML merge function for generated mapper XML files. This +will cause the generator to respect the overwrite flag for XML files in the same way it does +for Java files - if overwrite is true, then an existing file will be overwritten, else a +new file will be written with a unique name.

+

This plugin can be helpful if you disable all comments.

+ +

org.mybatis.generator.plugins.VirtualPrimaryKeyPlugin

+

This plugin can be used to specify columns that act as primary +keys, even if they are not defined as primary key in the database. +This is useful in the case where the database table does not have a +primary defined. Normally, MBG will generate a very limited +set of methods if there is no primary key. This plugin can be +used to enable generation of the full compliment of MBG methods.

+

To use the plugin, add the property "virtualKeyColumns" to your +<table> configuration and set the value to a comma or space +delimited list of column names that should be treated as primary +keys. The column names must exactly match the column names +returned from the database (typically all UPPERCASE). For example:

+
+  <table tableName="foo">
+    <property name="virtualKeyColumns" value="ID1, ID2" />
+  </table>
+
+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/running/running.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/running/running.xhtml new file mode 100644 index 0000000000..b7aaa88c3a --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/running/running.xhtml @@ -0,0 +1,60 @@ + + + + + + Running MyBatis Generator + + + +

Running MyBatis Generator

+

MyBatis Generator (MBG) can be run in the following ways:

+ +

Each method is described in detail on the linked pages.

+

Note: there is also an Eclipse +plugin for MBG that adds extra function - namely good integration into Eclipse, +an Eclipse enabled Ant task, and support for automatic merging of +Java files. See the +MyBatis +web site page for information on installing the Eclipse plugin.

+ +

Important: When running outside of an IDE environment like Eclipse, + MBG interprets the targetProject and + targetPackage attributes in all XML configurations as follows:

+
    +
  • targetProject is assumed to be an existing directory structure. + MBG will fail if this directory structure does not exist. There is one exception to this + rule - when MBG is running through the Maven plugin. See the Maven plugin page + for information about how targetProject is interpreted in Maven.
  • +
  • targetPackage will be translated to a suitable subdirectory + structure of the targetProject + directory structure. MBG will create these subdirectories if necessary.
  • +
+ + \ No newline at end of file diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/running/runningFromCmdLine.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/running/runningFromCmdLine.xhtml new file mode 100644 index 0000000000..552ddc40d4 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/running/runningFromCmdLine.xhtml @@ -0,0 +1,95 @@ + + + + + + Running MyBatis Generator From a Command Prompt + + + +

Running MyBatis Generator From a Command Prompt

+

MyBatis Generator (MBG) may be run directly from a command prompt. The JAR manifest includes the + name of the default class (org.mybatis.generator.api.ShellRunner) + or you may specify it yourself. The ShellRunner + class accepts several arguments as detailed below:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ArgumentValue
-configfile file_name
(required)
Specifies the name of the configuration file.
-overwrite (optional)If specified, then existing Java files will be overwritten if an existing Java + file if found with the same name as a generated file. If not specified, and a + Java file already exists with the same name as a generated file, then MBG + will write the newly generated Java file to the proper directory with a + unique name (e.g. MyClass.java.1, MyClass.java.2, etc.). + Important: The generator will always merge and overwrite XML files.
-verbose (optional)If specified, then progress messages will be written to the console.
-forceJavaLogging (optional)If specified, then MBG will use Java logging rather than Log4J even if + Log4J is in the runtime classpath.
-contextids context1,context2,...
(optional)
If specified, then this is a comma delimited list of contexts to use in + the current run. Any id specified in the list must exactly + match the value of the id attribute of an + <context> configuration element. Only ids specified + in this list will be active for this run. If this argument + is not specified, then all contexts will be active.
-tables table1, table2,...
(optional)
If specified, then this is a comma delimited list of tables to use in + the current run. Any table specified in the list must exactly + match the fully qualified table name specified in a + <table> configuration element. Only tables specified + in this list will be active for this run. If this argument + is not specified, then all tables will be active. + Specify table names as:

+ table
+ schema.table
+ catalog..table
+ etc.
+ +

You must create an XML configuration file to run MBG from the + command line. If the file is + named "generatorConfig.xml", then any of the following command lines will run + MBG:

+
+   java -jar mybatis-generator-core-x.x.x.jar -configfile generatorConfig.xml
+   java -jar mybatis-generator-core-x.x.x.jar -configfile generatorConfig.xml -overwrite
+   java -cp mybatis-generator-core-x.x.x.jar org.mybatis.generator.api.ShellRunner -configfile generatorConfig.xml
+   java -cp mybatis-generator-core-x.x.x.jar org.mybatis.generator.api.ShellRunner -configfile generatorConfig.xml -overwrite
+
+ + \ No newline at end of file diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithAnt.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithAnt.xhtml new file mode 100644 index 0000000000..786f317f9c --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithAnt.xhtml @@ -0,0 +1,116 @@ + + + + + + Running MyBatis Generator With Ant + + + +

Running MyBatis Generator With Ant

+

MyBatis Generator (MBG) includes a simple Ant task. The task must be defined in your + build.xml file, and the task accepts several parameters. Here is an example + build.xml file:

+
+   <project default="genfiles" basedir=".">
+     <property name="generated.source.dir" value="${basedir}" />
+
+     <target name="genfiles" description="Generate the files">
+       <taskdef name="mbgenerator"
+                classname="org.mybatis.generator.ant.GeneratorAntTask"
+                classpath="mybatis-generator-core-x.x.x.jar" />
+       <mbgenerator overwrite="true" configfile="generatorConfig.xml" verbose="false" >
+         <propertyset>
+           <propertyref name="generated.source.dir"/>
+         </propertyset>
+       </mbgenerator>
+     </target>
+   </project>
+
+ +

MyBatis Generator task attributes are as follows:

+ + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeValue
configfile (required)Specifies the name of the configuration file.
overwrite (optional)If "true", "yes", etc., then MBG will overwrite existing Java files if an existing Java + file if found with the same name as a generated file. If "false", "no", etc., and a + Java file already exists with the same name as a generated file, then MBG + will write the newly generated Java file to the proper directory with a + unique name (e.g. MyClass.java.1, MyClass.java.2, etc.). + Important: MBG will always merge and overwrite XML files.
contextids (optional)If specified, then this is a comma delimited list of contexts to use in + the current run. Any id specified in the list must exactly + match the value of the id attribute of an + <context> configuration element. Only ids specified + in this list will be active for this run. If this argument + is not specified, then all contexts will be active.
tables (optional)If specified, then this is a comma delimited list of tables to use in + the current run. Any table specified in the list must exactly + match the fully qualified table name specified in a + <table> configuration element. Only tables specified + in this list will be active for this run. If this argument + is not specified, then all tables will be active. + Specify table names as:

+ table
+ schema.table
+ catalog..table
+ etc.
verbose (optional)If "true", "yes", etc., then MBG will log progress messages to the + ant console (if Ant is running in verbose mode). The default is "false".
+ +

Notes:

+
    +
  • The classpath on the <taskdef> is used to tell Ant where the MBG JAR file + is. This is optional if you add MBG to the Ant classpath in one + of the other ways described in the Ant manual
  • +
  • The name of the task can be anything you desire, "mbgenerator" is + simply an example
  • +
  • The task supports an optional nested <propertyset> element which + is the standard Ant property set type. This can be used to pass parameters into + a configuration file. For example, the above property + generated.source.dir can be + accessed in the configuration file with the escape sequence + ${generated.source.dir} +
  • +
  • If a property is specified in the configuration file and is not resolved, + then the escaped property string will be passed "as is" into the generated code. +
  • +
+ + \ No newline at end of file diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithEclipse.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithEclipse.xhtml new file mode 100644 index 0000000000..abef935c8a --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithEclipse.xhtml @@ -0,0 +1,74 @@ + + + + + + Running MyBatis Generator with Eclipse + + + +

Running MyBatis Generator with Eclipse

+

Installing the Eclipse Feature

+

The eclipse feature can be installed in any of the following ways:

+
    +
  • Search for "MyBatis Generator" in the Eclipse marketplace and install directly from + the marketplace. You can access the eclipse marketplace in two ways: +
      +
    1. Take the menu option Help>Eclipse Marketplace... in a running eclipse instance
    2. +
    3. Go to https://marketplace.eclipse.org/
    4. +
    +
  • +
  • Manually configure an update site that points to + https://mybatis.jfrog.io/artifactory/generator-eclipse-release/
  • +
  • Download the zipped eclipse update site from the GitHub release page + (https://github.com/mybatis/generator/releases), unzip, and configure + an update site that points to your unzipped directory.
  • +
+

Using the Eclipse Feature

+

To get up and running quickly with MyBatis Generator in the eclipse environment, follow these steps:

+
    +
  1. Create a configuration file: +
      +
    1. File>New>Other...
    2. +
    3. Select "MyBatis Generator Configuration File" from the "MyBatis" + category, then press "Next"
    4. +
    5. Specify the location of the file, and the name of the file (defaults to generatorConfig.xml)
    6. +
    7. Finish the wizard
    8. +
    +
  2. +
  3. Fill out the configuration file appropriately. At a minimum, you must specify: +
      +
    1. jdbcConnection information to specify how to connect to the target database
    2. +
    3. A target package, and target project for the javaModelGenerator
    4. +
    5. A target package, and target project for the sqlMapGenerator
    6. +
    7. A target package, target project, and type for the javaClientGenerator (or you can remove the + javaClientGenerator element if you don't wish to generate Java Clients)
    8. +
    9. At least one database table
    10. +
    +
  4. +
  5. Save the file
  6. +
  7. Right click on the configuration file in Eclipse's navigator, or package explorer, view and take the + menu option "Run As>Run MyBatis Generator"
  8. +
+

Important Note: + MyBatis Generator in eclipse will not overwrite any custom changes you make to the objects it generates. You can + run it over and over again without fear of losing custom changes.

+ + \ No newline at end of file diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithJava.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithJava.xhtml new file mode 100644 index 0000000000..eaf2ffa256 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithJava.xhtml @@ -0,0 +1,80 @@ + + + + + + Running MyBatis Generator With Java + + + +

Running MyBatis Generator With Java

+

MyBatis Generator (MBG) may be invoked directly from Java. For configuration, +you may use either an XML configuration file, or configure MBG completely with +Java.

+

Running MBG from Java with an XML Configuration File

+

The following code sample shows how to call MBG from Java with an XML based configuration. + It does not + show exception handling, but that should be obvious from the compiler + errors :)

+
+   List<String> warnings = new ArrayList<String>();
+   boolean overwrite = true;
+   File configFile = new File("generatorConfig.xml");
+   ConfigurationParser cp = new ConfigurationParser(warnings);
+   Configuration config = cp.parseConfiguration(configFile);
+   DefaultShellCallback callback = new DefaultShellCallback(overwrite);
+   MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
+   myBatisGenerator.generate(null);
+
+ +

Notes:

+
    +
  • Configuration file properties may be passed to the parser as a parameter on + the ConfigurationParser constructor. If not passed explicitly, the JVM + system properties will be searched for the value of configuration file + properties. For example, the property + generated.source.dir can be + accessed in the configuration file with the escape sequence + ${generated.source.dir} +
  • +
  • If a property is specified in the configuration file and is not resolved, + then the escaped property string will be passed "as is" into the generated code. +
  • +
+ +

Running MBG from Java with a Java Based Configuration

+

The following code sample shows how to call MBG from Java with a Java based configuration. + It does + not show exception handling, but that should be obvious from the compiler + errors :)

+
+   List<String> warnings = new ArrayList<String>();
+   boolean overwrite = true;
+   Configuration config = new Configuration();
+
+   //   ... fill out the config object as appropriate...
+
+   DefaultShellCallback callback = new DefaultShellCallback(overwrite);
+   MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
+   myBatisGenerator.generate(null);
+
+ + + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithMaven.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithMaven.xhtml new file mode 100644 index 0000000000..afd0a49d02 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/running/runningWithMaven.xhtml @@ -0,0 +1,341 @@ + + + + + + Running MyBatis Generator With Maven + + + +

Running MyBatis Generator With Maven

+

MyBatis Generator (MBG) includes a Maven plugin for integration into a maven build. In +keeping with Maven's configuration by convention strategy, including MBG +in a Maven build can be very simple. The minimum configuration is shown below:

+ +
+   <project ...>
+     ...
+     <build>
+       ...
+       <plugins>
+        ...
+        <plugin>
+          <groupId>org.mybatis.generator</groupId>
+          <artifactId>mybatis-generator-maven-plugin</artifactId>
+          <version>1.4.1</version>
+        </plugin>
+        ...
+      </plugins>
+      ...
+    </build>
+    ...
+  </project>
+
+
+ +

Of course, things are never that easy!

+ +

Maven Goal and Execution

+

The MBG Maven plugin includes one goal:

+
    +
  • mybatis-generator:generate
  • +
+

The goal is not automatically executed by Maven. It can be executed in two +ways.

+

The goal can be executed from the command line with the command:

+
    +
  • mvn mybatis-generator:generate
  • +
+

You can pass parameters to the goal with standard Maven command line properties. +For example:

+
    +
  • mvn -Dmybatis.generator.overwrite=true mybatis-generator:generate
  • +
+

This will run MBG and instruct it to overwrite any existing Java files +it may find.

+

In a continuous build environment, you may want to automatically execute +MBG as a part of a Maven build. This can be accomplished by configuring +the goal to execute automatically. An example of this is shown below:

+
+   <project ...>
+     ...
+     <build>
+       ...
+       <plugins>
+        ...
+        <plugin>
+          <groupId>org.mybatis.generator</groupId>
+          <artifactId>mybatis-generator-maven-plugin</artifactId>
+          <version>1.4.1</version>
+          <executions>
+            <execution>
+              <id>Generate MyBatis Artifacts</id>
+              <goals>
+                <goal>generate</goal>
+              </goals>
+            </execution>
+          </executions>
+        </plugin>
+        ...
+      </plugins>
+      ...
+    </build>
+    ...
+  </project>
+
+
+

The MBG plugin is bound to the generate-sources phase of a +Maven build, so it will execute before the compile step. Also note that +MBG generates both Java source files and XML resources. The MBG goal +will bind both generated Java files and XML resources to the build and they +will both be included in any JAR generated by the build.

+ +

MyBatis Generator Configuration Properties

+

Any property specified in the POM will be passed into the configuration +file and may be used in the normal way. For example:

+
+   <project ...>
+     ...
+     <properties>
+       <dao.target.dir>src/main/java</dao.target.dir>
+     </properties>
+     ...
+     <build>
+       ...
+       <plugins>
+        ...
+        <plugin>
+          <groupId>org.mybatis.generator</groupId>
+          <artifactId>mybatis-generator-maven-plugin</artifactId>
+          <version>1.4.1</version>
+          <executions>
+            <execution>
+              <id>Generate MyBatis Artifacts</id>
+              <goals>
+                <goal>generate</goal>
+              </goals>
+            </execution>
+          </executions>
+        </plugin>
+        ...
+      </plugins>
+      ...
+    </build>
+    ...
+  </project>
+
+
+

In this case, the property may be accessed in the configuration file with the +syntax ${dao.target.dir}.

+ +

Classpath Issues

+

Initially, the plugin classpath is very limited - it only contains MyBatis generator itself. +If you need to add something to the plugin's classpath (for example, a JDBC driver), you can do it +by adding dependencies to the plugin configuration like this:

+
+   <project ...>
+     ...
+     <build>
+       ...
+       <plugins>
+        ...
+        <plugin>
+          <groupId>org.mybatis.generator</groupId>
+          <artifactId>mybatis-generator-maven-plugin</artifactId>
+          <version>1.4.1</version>
+          <executions>
+            <execution>
+              <id>Generate MyBatis Artifacts</id>
+              <goals>
+                <goal>generate</goal>
+              </goals>
+            </execution>
+          </executions>
+          <dependencies>
+            <dependency>
+              <groupId>org.hsqldb</groupId>
+              <artifactId>hsqldb</artifactId>
+              <version>2.3.4</version>
+            </dependency>
+          </dependencies>
+        </plugin>
+        ...
+      </plugins>
+      ...
+    </build>
+    ...
+  </project>
+
+
+

If the dependencies you need are already included as dependencies of the project, then you can also +use one of the configuration parameters related to the plugin classpath - "includeCompileDependencies" or +"includeAllDependencies" see below for details about those properties.

+ +

Parameter Reference

+

All parameters are optional and most have suitable defaults.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParameterExpressionTypeComments
configurationFile${mybatis.generator.configurationFile}java.io.FileThe location of the XML configuration file. +

Default value:

+ ${basedir}/src/main/resources/generatorConfig.xml +
contexts${mybatis.generator.contexts}java.lang.StringA comma delimited list of contexts to use in the current run. + Any id specified in the list must exactly match the value of the id + attribute of an <context> configuration element. + Only ids specified in this list will be active for this run. + If this parameter is not specified, then all contexts will be active. +
jdbcDriver${mybatis.generator.jdbcDriver}java.lang.StringIf you specify a sqlScript, then this is the + fully qualified JDBC driver class name to use when connecting to the + database. +
jdbcPassword${mybatis.generator.jdbcPassword}java.lang.StringIf you specify a sqlScript, then this is the + password to use when connecting to the database. +
jdbcURL${mybatis.generator.jdbcURL}java.lang.StringIf you specify a sqlScript, then this is the + JDBC URL to use when connecting to the database. +
jdbcUserId${mybatis.generator.jdbcUserId}java.lang.StringIf you specify a sqlScript, then this is the + JDBC user ID to use when connecting to the database. +
outputDirectory${mybatis.generator.outputDirectory}java.io.FileThe directory where files generated by MBG will be placed. + This directory is used whenever a targetProject in the + configuration file is set to the special value "MAVEN" (case sensitive). +

Default value:

+ ${project.build.directory}/generated-sources/mybatis-generator +
overwrite${mybatis.generator.overwrite}booleanIf true, then existing Java files will be overwritten if an + existing Java file if found with the same name as a generated file. If not + specified, and a Java file already exists with the same name as a generated + file, then MBG will write the newly generated Java file to the proper + directory with a unique name (e.g. MyClass.java.1, MyClass.java.2, etc.). + Important: MBG will always merge and overwrite XML files. +

Default value:

+ false +
sqlScript${mybatis.generator.sqlScript}java.lang.StringLocation of a SQL script file to run before generating code. + If null, then no script will be run. If not null, then jdbcDriver, + jdbcURL must be supplied also. In addition, + jdbcUserId and jdbcPassword may be supplied if + the database requires authentication. +

Value can be specified as a location in the file system or, if prefixed with "classpath:" + a location on the build classpath.

+
tableNames${mybatis.generator.tableNames}java.lang.StringIf specified, then this is a comma delimited list of tables to + use in the current run. Any table specified in the list must exactly + match the fully qualified table name specified in a <table> configuration + element. Only tables specified in this list will be active for this run. + If this argument is not specified, then all tables will be active. + Specify table names as: +

table
+ schema.table
+ catalog..table
+ etc.

+
verbose${mybatis.generator.verbose}booleanIf true, then MBG will write progress messages to the + build log. +
includeCompileDependencies${mybatis.generator.includeCompileDependencies}booleanIf true, then dependencies with scope "compile", "provided", and "system" will be + added to the generator's classpath. +
includeAllDependencies${mybatis.generator.includeAllDependencies}booleanIf true, then dependencies with any scope will be + added to the generator's classpath. +
+ +

Interpretation of targetProject

+

The targetProject attribute of the generator configurations is interpreted +differently when running with Maven. If set to the special value "MAVEN" (case +sensitive), then targetProject will be set to the plugin's output directory, +and that directory will be created if it doesn't already exist. If not set to "MAVEN", then +targetProject will be interpreted as normal by MBG - it must be set +to a directory that already exists.

+ + \ No newline at end of file diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/usage/db2.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/usage/db2.xhtml new file mode 100644 index 0000000000..252c85d283 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/usage/db2.xhtml @@ -0,0 +1,40 @@ + + + + + + DB2 Usage Notes + + + +

DB2 Usage Notes

+

LONG VARCHAR Fields

+

By default MyBatis Generator will map LONG VARCHAR fields to the java.lang.String data type, +and will mark these fields as jdbcType="LONGVARCHAR". This +mapping will cause errors when retrieving data from DB2. DB2 LONG VARCHAR fields should be mapped +to the java.lang.String data type with jdbcType="VARCHAR". To overcome +this problem, use a <columnOverride> as follows:

+
+  <table schema="DB2ADMIN" tableName="ALLTYPES" >
+    <columnOverride column="LONG_VARCHAR_FIELD" javaType="java.lang.String" jdbcType="VARCHAR" />
+  </table>
+
+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/usage/intro.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/usage/intro.xhtml new file mode 100644 index 0000000000..cd7fc5ca2d --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/usage/intro.xhtml @@ -0,0 +1,40 @@ + + + + + + Usage Notes + + + +

Usage Notes

+

This section collects usage information for different databases.

+ + +

Please let us know about any quirks you discover for the database you are using - we will +be happy to add the information +to this section for future reference.

+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/usage/mysql.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/usage/mysql.xhtml new file mode 100644 index 0000000000..82a97221d2 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/usage/mysql.xhtml @@ -0,0 +1,60 @@ + + + + + + MySql Usage Notes + + + +

MySql Usage Notes

+

Unsigned Fields

+

MySql supports both signed, and unsigned, numeric fields. These are not JDBC types, so MyBatis +generator cannot automatically account for these types of fields. The Java data types are always signed. +This can +lead to a loss of precision when using unsigned fields. The solution is to provide a +<columnOverride> for any unsigned numeric field in MySql. Here is an example +of how to deal with an unsigned bigint field in MySql:

+
+  <table tableName="ALLTYPES" >
+    <columnOverride column="UNSIGNED_BIGINT_FIELD" javaType="java.lang.Object" jdbcType="LONG" />
+  </table>
+
+

You will have to cast the returned value to the appropriate type yourself (in this case, +java.math.BigInteger).

+

Catalogs and Schema

+

MySql does not properly support SQL catalogs and schema. If you run the create schema +command in MySql, it actually creates a database - and the JDBC driver reports it back as a catalog. +But MySql syntax does not support the standard catalog..table SQL syntax.

+

For this reason, it is best to not specify either catalog or schema in generator configurations. +Just specify table names and specify the database in the JDBC URL.

+

If you are using version 8.x of Connector/J you may notice that the generator attempts to generate code +for tables in the MySql information schemas (sys, information_schema, performance_schema, etc.) This is +probably not what you want! To disable this behavior, add the property "nullCatalogMeansCurrent=true" to +your JDBC URL.

+

For example:

+
+    <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/my_schema"
+            userId="my_user" password="my_password">
+        <property name="nullCatalogMeansCurrent" value="true" />
+    </jdbcConnection>
+
+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/usage/oracle.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/usage/oracle.xhtml new file mode 100644 index 0000000000..42d1daedf6 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/usage/oracle.xhtml @@ -0,0 +1,47 @@ + + + + + + Oracle Usage Notes + + + +

Oracle Usage Notes

+

Public Synonyms

+

If you want to generate objects for a table that has a public synonym, you +should actually generate the objects against the real table - and then change the +table name at runtime. MyBatis Generator supports this automatically.

+

For example, assume there is a public alias "FRED" that points to the +table "HR.EMPLOYEES". The following table configuration will generate the objects +based on HR.EMPLOYEES, but the runtime SQL will only refer to FRED:

+
+  <table schema="HR" tableName="EMPLOYEES">
+    <property name="ignoreQualifiersAtRuntime" value="true" />
+    <property name="runtimeTableName" value="FRED" />
+  </table>
+
+

Oracle LONG Datatype

+

The Oracle JDBC driver will report that a LONG column is JDBC type LONGVARCHAR. +MyBatis will map LONGVARCHAR to CLOB which is unsupported by the Oracle driver. +So, when using LONG datatype, you should do a column override in the generator +to map it to VARCHAR JDBC type.

+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/usage/postgresql.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/usage/postgresql.xhtml new file mode 100644 index 0000000000..adf97a9531 --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/usage/postgresql.xhtml @@ -0,0 +1,57 @@ + + + + + + PostgreSQL Usage Notes + + + +

PostgreSQL Usage Notes

+

Case Sensitivity

+

PostgreSQL is case sensitive with regards to all database identifiers +(table names, schema names, column names, etc.) In addition, PostgreSQL +has a distinct preference for all identifiers being in all lower case letters. +If you use all lower case identifiers for PostgreSQL, then MyBatis Generator will find tables +and write correct SQL with no additional consideration. If you used mixed cased, +or upper case, identifiers you will +need to configure MyBatis Generator appropriately:

+
    +
  • Use the delimitIdentifiers option if your table or schema + is mixed case or all upper case.
  • +
  • For each mixed case or upper case column you could specify a + <columnOverride> element to specifically delimit the column, + or you could specify the delimitAllColumns attribute + to delimit all column names.
  • +
+

Examples:

+
+  <table schema="HR" tableName="Employees"
+      delimitIdentifiers="true" delimitAllColumns="true"/>
+
+

Or...

+
+  <table schema="HR" tableName="Employees" delimitIdentifiers="true" >
+    <columnOverride column="EmployeeId" delimitedColumnName="true" />
+    <columnOverride column="EmployeeName" delimitedColumnName="true" />
+  </table>
+
+ + diff --git a/core/mybatis-generator-core/src/site/zh/xhtml/whatsNew.xhtml b/core/mybatis-generator-core/src/site/zh/xhtml/whatsNew.xhtml new file mode 100644 index 0000000000..9e8dc77bab --- /dev/null +++ b/core/mybatis-generator-core/src/site/zh/xhtml/whatsNew.xhtml @@ -0,0 +1,910 @@ + + + + + + MyBatis Generator 的新变化 + + + +

What's New in MyBatis Generator

+

Version 1.4.2

+ +

Enhancements

+
    +
  • The generator now uses annotations from the "jakarta" namespace in favor over the "javax" namespace. This is + recommended for JDK 9+. If you prefer to use the "javax" annotations, there is a new property on the + <commentGenerator> element that will override this behavior. +
  • +
+ + +

Version 1.4.1

+

This release is primarily focused on updating the runtimes for MyBatis Dynamic SQL ("MyBatis3DynamicSQL" and +"MyBatis3Kotlin"). The generated code for "MyBatis3DynamicSQL" is now dependent on MyBatis Dynamic SQL version 1.3.1 or +later. The generated code for "MyBatis3Kotlin" is now dependent on MyBatis Dynamic SQL version 1.4.0 or later. See +below for details about these changes. See the GitHub page for milestone 1.4.1 for details other changes in this +release: +Milestone 1.4.1.

+ +

Updated MyBatis Dynamic SQL Runtimes

+

The MyBatis3DynamicSQL and MyBatis3Kotlin runtimes have been updated to generate code that requires updated versions +of MyBatis Dynamic SQL. Generated Java code requires version 1.3.1 or later, generated Kotlin code requires version +1.4.0 or later. This should be a relatively minor change for most Java users +and should simply require updating the MyBatis Dynamic SQL version to 1.3.1 or later.

+ +

For both Java and Kotlin users, the new database model classes (a.k.a. the "support" classes) now extend + AliasableSqlTable. This allows you to specify a table alias directly within an instance + of a table class, rather than specifying the alias in a select statement. This can make the code a bit clearer + if you are doing a self join. +

+ +

Differences for Kotlin users are more extensive. As a result of the changes detailed below, several plugin +methods related to the generated Kotlin files have changed or been deprecated. If a method has been deprecated, +it is no longer in use by the generator and will be removed in the future.

+ +

We have merged the generated mapper extension methods into the same file as the mapper itself - eliminating +generated files with the word "Extensions" in their names. If you are regenerating code in an existing project, +you should manually delete the old generated extension files (generated Kotlin files with the word "Extensions" +in the file name). +

+ +

The generated Dynamic SQL Support class in the Kotlin runtime +has changed and now matches the recommended format published in the MyBatis Dynamic SQL documentation (it more closely +matches the style of the support class generated for Java). +This has the following benefits:

+ +
    +
  • Self-joins are now possible with the generated code
  • +
  • There is no longer a need to append the word "Record" to generated model classes
  • +
  • Specifying an override to rename the domain object will take effect as desired
  • +
+ +

This update will require changes in existing code if you regenerate Kotlin code using this updated version.

+ +

Generated Kotlin data classes no longer have the word "Record" appended to their names. Otherwise, they are +the same. Your use of these classes will need to change. In most cases, you can simply remove the word "Record" from the +reference. For example, if you have a table named "Bar", you may see code like this:

+
+    import foo.BarRecord
+
+    val bar = BarRecord(1, 2)
+
+ +

It will need to change to code like this:

+
+    import foo.Bar           // remove "Record"
+
+    val bar = Bar(1, 2)      // remove "Record"
+
+ +

Additionally, generated support classes now declare an instance of the AliasableSqlTable object, +and all fields, as values in the top level object. If you wrote custom code that used these generated objects, two +changes will be required:

+ +
    +
  • The declared AliasableSqlTable object is now an instance of an inner Class rather than an inner + Object. It should be referenced with the new name (typically the same name as previously, with the first letter + now lowercase)
  • +
  • References to any AliasableSqlColumn should reference the top level value rather than a nested + value
  • +
+ +

For example, previously code might have looked like this:

+
+    import foo.BarDynamicSqlSupport.Bar
+    import foo.BarDynamicSqlSupport.Bar.id
+    import foo.BarDynamicSqlSupport.Bar.description
+
+    val selectStatement = select(id, description) {
+       from(Bar)
+    }
+
+ +

New code should look like this:

+
+    import foo.BarDynamicSqlSupport.bar           // use the lower case name
+    import foo.BarDynamicSqlSupport.id            // import the top level field
+    import foo.BarDynamicSqlSupport.description   // import the top level field
+
+    val selectStatement = select(id, description) {
+       from(bar)     // use the lower case name
+    }
+
+ +

Lastly, the generated Kotlin code uses upgraded DSL features that should be mostly transparent. But you will notice + that any "where" clauses you write will likely have deprecation warnings. This is due to a change in MyBatis + Dynamic SQL. You can read about remediation of these warnings in the documentation for that project. +

+ +

Other Enhancements

+
    +
  • Added capabilities to the SerializablePlugin for Kotlin
  • +
  • Added the ability to specify a package for MyBatis Dynamic SQL Support Classes
  • +
  • Added the ability to specify a MyBatis Dynamic SQL Support class name on the table configuration
  • +
  • Added a plugin to generate @CacheNamespace annotations
  • +
  • Added the ability to specify a name for the inner class generated in the MyBatis Dynamic SQL support class
  • +
  • Added plugin methods that allow generation of any arbitrary file type
  • +
  • Added a property to <columnOverride> that forces the Java type into generated mappings for the + MyBatis Dynamic SQL based runtimes. This is useful in certain cases such as when you use MyBatis' + EnumOrdinalTypeHandler. +
  • +
+ +

Removed Items

+
    +
  • Removed the deprecated MyBatis3DynamicSqlV1 runtime
  • +
  • Removed the Java client property "useLegacyBuilder" as it created code that has been deprecated + in MyBatis since version 3.2
  • +
  • Removed support for Log4J version 1.x
  • +
+ +

Version 1.4.0

+

This is a major change with these themes:

+
    +
  • New Runtime for Kotlin using MyBatis Dynamic SQL
  • +
  • New Runtime for Java using MyBatis Dynamic SQL
  • +
  • MyBatis Dynamic SQL is now the default runtime
  • +
  • Move to Java 8
  • +
  • Remove support for iBatis2
  • +
  • General code cleanup
  • +
  • Several minor enhancements and bug fixes. See the GitHub page for milestone 1.4.0 for details. + Milestone 1.4.0
  • +
+ +

New Runtime for Kotlin Using MyBatis Dynamic SQL

+

MyBatis generator supports Kotlin! There is a new simple DOM for generating Kotlin. There is also a new runtime that will +generate Kotlin code that uses the MyBatis Dynamic SQL library. It has functionality that matches the new Java runtime +for MyBatis Dynamic SQL (see below) - but it uses a more idiomatic Kotlin style with receiver functions rather than the +method chaining style of the Java runtime. +

+ +

To use the new runtime, set targetRuntime=MyBatis3Kotlin on a <context>.

+ +

As in the Java runtime for MyBatis Dynamic SQL, there is no Example class generated and the *ByExample methods are not +generated. Rather +general count, delete, insert, selectOne, selectMany, and update methods are generated that allow where clauses and other +parts of SQL statements to be supplied via lambdas.

+ +

See the MyBatis Dynamic SQL with Kotlin Usage Page for further details.

+ +

New Runtime for MyBatis Dynamic SQL

+

There is a new runtime for MyBatis Dynamic SQL. It uses improved functionality in that library and requires +version 1.1.3 or later of that library.

+ +

To use the new runtime, set targetRuntime=MyBatis3DynamicSql on a <context>.

+ +

Important: Setting targetRuntime=MyBatis3DynamicSql will use the new runtime. If you wish to use +the original runtime, set targetRuntime=MyBatis3DynamicSqlV1. However, note that the V1 runtime is +deprecated and will be removed in a future version - so please switch to the new runtime.

+ +

The new runtime has enhanced capabilities:

+
    +
  • The *ByExample methods are removed. There is no example class generated in this runtime and the old method names + don't make sense anymore. They are replaced + by general count/delete/select/update methods that allow a where clause to be added via a lambda
  • +
  • There is a new multiple row insert method that leverages recent enhancements in MyBatis and MyBatis Dynamic SQL
  • +
  • There is a new selectOne method that allows you to specify a where clause via a lambda. This is convenient + when you know that there will only be one record returned from a query - you no longer have to receive a list + with one element
  • +
  • selectByPrimaryKey and selectOne return Optional<R> rather than an object that may be null
  • +
  • The new generated update method is far more flexible than the prior version. It can be used to mimic the old + updateByExample and updateByExampleSelective methods, but it can also be used to generate update methods with any + combination of update columns. So, for example, you can create an update statement that will insert nulls into some + fields and ignore other fields. This has been an ongoing frustration with the prior update methods and is now resolved.
  • +
+ +

See the MyBatis Dynamic SQL Usage Page for further details.

+ +

Breaking API Changes

+
    +
  • Removed Plugin methods that were specific to iBatis2 (these were the clientXXXGenerated + methods that accepted a TopLevelClass as a parameter).
  • +
  • Changed the signature of the Plugin clientGenerated method.
  • +
  • Removed the toXmlElement methods in the configuration classes. These methods were never properly + implemented.
  • +
  • In the Java DOM, the Method class now requires an explicit call to setAbstract + to mark the method as an abstract method. This was done to support private methods in interfaces for Java9+ + code.
  • +
  • In the Java DOM, removed the default constructors for Method and Field
  • +
  • Removed several methods from CompilationUnit including isJavaInterface, + isJavaEnumeration, getSuperClass, and getSuperInterfaceTypes.
  • +
  • In the XML DOM, element nodes no longer extend the abstract Element class which is removed.
  • +
  • Changed return types to Optionals in the DOM methods where appropriate.
  • +
  • Removed the getFormattedContent method from all Java and XML DOM classes. These methods + are replaced by a new set of renderer classes. Note that the new renderer classes will produce + code that is the same as the prior methods with very few exceptions - and those exceptions are related to + bugs in the old methods.
  • +
  • The attribute "implementationPackage" has been removed from the <javaClientGenerator> + configuration. It was only used for iBatis.
  • +
+ +

Other Changes

+
    +
  • Support for iBatis2 removed
  • +
  • Support for parsing old Ibator configuration files removed
  • +
  • Removed SqlMapConfigPlugin as that was specific to iBatis2
  • +
  • Added ability to specify a different project and package for generated model objects
  • +
  • Expanded the capabilities of the Java DOM and fixed a few inconsistencies
  • +
+ +

Version 1.3.7

+

This version contains several minor fixes and enhancements - mostly related to the MyBatis3DynamicSql runtime.

+ +

Please reference the GitHub page for milestone 1.3.7 for details. +Milestone 1.3.7 +

+ +

Version 1.3.6

+

Major Enhancement

+

The major enhancement in this release is a new type of generated code. The generator will now create code that +is based on the MyBatis Dynamic SQL library. +From the first release of MyBatis Generator, the generator has created code that includes "by example" support, but that support +has been limited and difficult to use. The new style of generated code supports a more natural SQL-like syntax for WHERE clauses. +Additionally, WHERE clauses can be created with any combination of ANDs and ORs. This is a significant improvement to the generated +code. It comes at the cost of dependency on MyBatis Dynamic SQL, and loss of compatibility with previously generated code, but we +think it will be worth the change. One other benefit is that the generated code is significantly smaller and easier to understand. +

+

Don't worry - unless you enable this change, then generator will create code exactly as it has in the past.

+

To enable the change, use the new "MyBatis3DynamicSQL" runtime on the + <context> configuration element. To read more about using this new + style of generated code, see the + MyBatis Dynamic SQL Usage Notes page.

+ +

Other Announcements

+
    +
  • After this release, support for iBatis2 code generation will be removed
  • +
  • After this release, the generator will require Java 8 to run. It will still generate code for earlier + Java versions, but the generator itself will require Java 8.
  • +
+ +

Other Fixes/Enhancements

+

Please reference the GitHub page for milestone 1.3.6 for details on what else +has changed in this release. +Milestone 1.3.6 +

+ +

Version 1.3.5

+

Fixes/Enhancements

+

Please reference the GitHub page for milestone 1.3.5 for details on what +has changed in this release. +Milestone 1.3.5 +

+ +

Version 1.3.4

+

Announcements

+

In this release we have deprecated the popup menu item in the eclipse plugin for +running MyBatis generator and it will be removed in the next release. The replacement +is a new MyBatis generator launcher that has far more capabilities than the popup +menu item.

+ +

Fixes/Enhancements

+

Please reference the GitHub page for milestone 1.3.4 for details on what +has changed in this release. +Milestone 1.3.4 +

+ +

Version 1.3.3

+

Announcements

+
    +
  • MyBatis Generator now requires JRE 1.6 or greater
  • +
+

Fixes/Enhancements

+

Please reference the GitHub page for milestone 1.3.3 for details on what +has changed in this release. +Milestone 1.3.3 +

+ +

Version 1.3.2

+

Bugs Fixed

+
    +
  • Add comments to generated constructors in the model classes + so they can be merged.
  • +
  • Support package names with Uppercase elements.
  • +
  • Fixed issue #288 - Incorrect annotated countByExample method
  • +
  • Fixed the Maven plugin so <properties> files can be found + in the project classpath.
  • +
  • Fixed issue #359 - make JdbcTypeInformation public
  • +
  • Fixed Context.toXmlElement() method to include missing attributes
  • +
  • Fixed CaseInsensitiveLikePlugin to add new methods to GeneratedCriteria inner class
  • +
  • Issue #412 - update the documentation to reflect the difference in MyBatis3 regarding + generated keys.
  • +
  • Issue #440 - incorrect code generated for primitives with type handlers
  • +
  • Issue #439 - use auto boxing for primitives when appropriate
  • +
  • Issue #438 - keep primary key properties in database sequence
  • +
  • Issue #507 - RowBounds plugin generates duplicate statements
  • +
  • Issue #593 - CaseInsensitiveLikePlugin skipped Jdbc4 National Character Types
  • +
+

Enhancements

+
    +
  • Added a new target runtime - MyBatis3Simple - that can be used to generate + very simple CRUD operations on tables. This runtime produces far simpler + MyBatis code than the normal MyBatis3 runtime. The produced code also has + lower functionality that the normal MyBatis3 runtime. If you do not + regularly use the "by example" methods, then the code produced by the + MyBatis3Siple runtime may be more suitable to your project.
  • +
  • Added a new plugin - VirtualPrimaryKey plugin - that can be used to specify + columns that act as a primary key, even if they are not defined as + primary keys in the database.
  • +
  • Issue #328 - Added a new plugin - RowBounds plugin - that will generate an additional + version of selectByExample that supports the MyBatis RowBounds + function.
  • +
  • Created a new reference page for supplied plugins: + Supplied Plugins
  • +
  • Issue #368 - Allowed for generation of Java Model only. If no SQLMapGenerator + or JavaClientGenerator is specified in a context, then only a Java Model is generated. + Also, if property "modelOnly" is set to "true" on a <table> element, then + only model object and, possibly XML result maps, will be generated. +
  • +
  • Issue #374 - Allow for specification of a file encoding for reading/writing + Java files on the file system. There is a new property "javaFileEncoding" on the + <context> element that can be used to specify a Java file encoding. (XML files + are always read/written in UTF-8 per the spec). +
  • +
  • Added the ability to specify custom code formatters for generated Java and XML files. + See new properties on the <context> element for more information. +
  • +
  • Added support for varargs to org.mybatis.generator.api.dom.java.Parameter + class +
  • +
  • Added support for synchronized and native to + org.mybatis.generator.api.dom.java.Method class +
  • +
  • Added support for transient and volatile to + org.mybatis.generator.api.dom.java.Field class +
  • +
  • Issue #375 - Added a new plugin - ToStringPlugin - that will generate a toString() method + in the model classes. Thanks Alexei and Iwao!
  • +
  • Issue #233 - added GWT capability to the Serializable plugin
  • +
  • Issue #564 - support subpackages at the table level
  • +
  • Issue #590 - new plugin for <cache>. Thanks Jason Bennett!
  • +
+ +

Version 1.3.1

+

Bugs Fixed

+
    +
  • Always specify <selectKey> order for MyBatis3 - position within + the <insert> is not relevant.
  • +
  • "rootInterface" was ignored for XMLMAPPER clients
  • +
  • Fixed bug when a lower case class name is specified as a domain object name
  • +
  • Fixed issue #174 - incorrect format of order by clause in + selectByExampleWithBlobs
  • +
+

Enhancements

+
    +
  • Added a new MyBatis3 generator that generates code based solely on annotations + with no generated XML. Configuration settings for this new generator are as follows: + +
  • +
  • Added a new MyBatis3 generator that generates code based on a mix of annotations + and generated XML. Configuration settings for this new generator are as follows: + +
  • +
  • Add support for JDBC types NCHAR, NCLOB, NVARCHAR to match MyBatis3.
  • +
  • Added support for "useGeneratedKeys" in MyBatis3. See + <generatedKey> + for details. +
  • +
  • Added support for immutable objects and constructor based result maps in + MyBatis3. See <table> + and/or <javaModelGenerator> + for details. +
  • +
  • Added support for initialization blocks in the Java DOM
  • +
  • Issue #214 - Added the ability to supress all comments in generated code. See + <commentGenerator> + for details. +
  • +
+ + +

Version 1.3.0

+
    +
  1. Moved to mybatis.org, renamed MyBatis Generator
  2. +
  3. MyBatis generator will continue to support XML configuration files + from Ibator. However, any new features will only be implemented in + MyBatis formatted configuration files. Some minimal changes are required to + migrate Ibator formatted configuration files to the new DTD for MyBatis Generator.
  4. +
  5. Configuration settings for MyBatis 3 are as follows: +
      +
    1. The targetRuntime attribute of + <context> + element must be changed to MyBatis3
    2. +
    3. The type attribute of + <javaClientGenerator> + element must be changed to XMLMAPPER
    4. +
    +
  6. +
  7. Removed support for suppressTypeWarnings property in the + <context> element. This confusing property has become + unmanagable due to confusion between @SuppressWarnings("unchecked") and + @SuppressWarnings("rawtypes") in the different compilers. This was only used + in the corner case where code generated with Ibatis2Java2 targetRuntime was to be compiled + with a JSE 5.0 compiler.
  8. +
+ +

Version 1.2.2 (Never Released)

+

Announcements

+
    +
  • The org.apache.ibatis.ibator.api.CommentGenerator interface + has changed. Classes that implement this interface must be changed. With + this change, implementing classes have access to many more data elements + from which to generate comments. Additionally, this change makes the comment + generator interface more consistent with the other public Ibator interfaces. + Details of the change follow: +
      +
    • Methods which accepted the parameter FullyQualifiedTable + now accept the parameter IntrospectedTable instead. + The FullyQualifiedTable instance is available through + the method IntrospectedTable.getFullyQualifiedTable(). +
    • +
    • Methods which accepted the String parameter columnName + now accept the parameter IntrospectedColumn instead. + The column name is available through + the method IntrospectedColumn.getActualColumnName(). +
    • +
    +

    Important Note: any implementation that subclasses the Ibator + supplied class DefaultCommentGenerator does not need to + change immediately with this release. + The old methods have been deprecated and will be removed with the next + release of Ibator - so subclasses should be reworked as soon as + convenient.

    +
  • +
  • The SQL Map generator has changed in that it no longer prepends the string + "ibatorgenerated_" to every generated XML id. If you were relying on these + generated names in other code, you can force Ibator to prepend the string + with the property useLegacyXMLIds on the + <SqlMapGenerator> configuration.
  • +
  • Ibator is now built with Maven and includes a Maven plugin
  • + +
+

Bugs Fixed

+
    +
  • NPE when no DAOs are generated.
  • +
  • IBATIS-579 - Don't allow column names that contain spaces to + break across lines in generated XML.
  • +
  • Fixed NPE and incorrect calculation in generated equals method + (from EqualsHashCodePlugin) when certain + fields are null - thanks to Benjamin Klatt for finding this bug.
  • +
  • IBATIS-601 - improper validation of <generatedKey>
  • +
  • IBATIS-609 - incorrect parsing of Java generic types
  • +
  • Fixed spelling error LONCVARCHAR to LONGVARCHAR (thanks Allard)
  • +
  • Fixed IBATIS-731 - change name of primary key variable to avoid conflicts
  • +
  • Fixed IBATIS-699 - Overwrite unmergeable XML files if enabled
  • +
  • Fixed issue where insertSelective failed if there is a sequence generating the + primary key (issue only with iBATIS3)
  • +
+ +

Enhancements

+
    +
  • IBATIS-569 - Modified the IbatorRules implementation to make it easier + for plugins to provide custom implementations of IbatorRules. See the + Javadoc for the new class + org.apache.ibatis.ibator.internal.rules.IbatorRulesDelegate + for more information.
  • +
  • IBATIS-571 - Added support for automatically delimiting SQL keywords + if they are used as column names in tables. See the + <ibatorContext> page + for more information.
  • +
  • IBATIS-577 - Define SQL fragments for column lists to improve + reusability of generated code. Thanks to Iwao AVE! for the idea + and the initial patch. +
  • +
  • Added new -verbose command line argument. See the + Running Ibator page + for more information.
  • +
  • Added logging statements for use in debug. See the + Logging page + for more information.
  • +
  • Added new example plugin to demonstrate adding case insensitive LIKE + support to generated Example classes. See the + <ibatorPlugin> page + for more information.
  • +
  • Added "delimitAllColumns" attribute to table configurations. This supports databases + like PosgreSQL that are case sensitive for identifiers. See the + <table> page + for more information.
  • +
  • Added a page explaining how to deal with case sensitivity in PostgreSQL. See the + PostgreSQL page + for more information.
  • +
  • IBATIS-586 - Added the ability to specify nested property elements on columnOverrides. + See the <columnOverride> page + for more information. Thanks to Dan Turkenkopf for the idea and a nice initial patch.
  • +
  • The IntrospectedColumn class now contains any column remarks returned during + database introspection. This may be useful for some CommentGenerators.
  • +
  • IBATIS-592 - Added attributes to IntrospectedTable that contain the calculated + SqlMap namespace, and the calculated runtime table names. These can now be overridden in + plugins.
  • +
  • Fixed addCriterionfor JDBC* methods so that they all do a null check.
  • +
  • Fixed IbatorRunner so that configuration errors are shown (thanks to Karel Rank)
  • +
  • IBATIS-605 - Added Informix Dialect for + <generatedKey>
  • +
  • Addedd support for "distinct" on select by example methods
  • +
  • Added new "or" method to example classes
  • +
  • Added new "useCompoundPropertyNames" property on <table>
  • +
  • Enabled a far simpler method for extending the example classes
  • +
  • EqualsHashCodePlugin now generates far superior methods
  • + +
+ +

Version 1.2.1

+

Bugs Fixed

+
    +
  • Fixed the IbatorObjectFactory so it will find internal classes from the context classloader.
  • +
  • Fixed IBATIS-565 - ill formed comment in the SqlMapConfigPlugin
  • +
+ +

Enhancements

+
    +
  • Modified plugin methods for model fields, getters, and setters so that + the plugin will know which type of class (Primary Key, Base Record, or + Record with BLOBs) is being generated.
  • +
  • Added methods to IntrospectedTable to get/set attributes. This + allows plugin classes to maintain table based state between + plugin calls.
  • +
  • Added initialized method to the plugin API. This + allows plugins to alter some of the fundamental code generation items + (like the name of a generated class, for example).
  • +
  • Added an example plugin to show usage of the initialized + method.
  • +
+ +

Version 1.2.0

+

Announcements

+
    +
  • With version 1.2, Abator is renamed to Apache iBATIS Ibator. Several changes + have been made to the XML configuration as well as the Java API. See the + Migrating from Abator page for detailed + information about changes needed to existing Abator configuration files.
  • +
+ +

Bugs Fixed

+
    +
  • Fixed the JavaTypeResolver so that columns with unsupported data types + may be overridden by configuration.
  • +
  • Fixed IBATIS-523 - a bug in the pre-release version of the EqualsHashCodePlugin
  • +
  • Fixed IBATIS-542 - upgrade the build to Ant version 1.7.1
  • +
+ +

Enhancements

+
    +
  • Ibator now includes a plugin mechanism. This mechanism can be used to + add to or modify the code generated by Ibator. If you have previously + extended one of Abator's code generators to change their behavior, we + strongly suggest that you move to a plugin. See the + <ibatorPlugin> page + for detailed information.
  • +
  • Ibator ships with the following plugins: +
      +
    • A plugin that will generate an SQL Map Config File + (org.apache.ibatis.ibator.plugins.SqlMapConfigPlugin) +
    • +
    • A plugin that will make generated model classes Serializable + (org.apache.ibatis.ibator.plugins.SerializablePlugin) +
    • +
    • A plugin that will add equals and hashCode + methods to generated model classes + (org.apache.ibatis.ibator.plugins.EqualsHashCodePlugin) +
    • +
    +
  • +
  • Added support for "runtimeCatalog" and "runtimeSchema" properties to the + <table> + configuration element. Thanks to Dan Turkenkopf for the idea and the + patch!
  • +
  • New generated method - insertSelective. This method will allow you to use + column defaults on a table definition on insert
  • +
  • Added the ability to specify a that DAO implementation classes be in a + separate package from the DAO interface classes.
  • +
+ +

Changes from Abator

+

There are several breaking changes between Ibator and Abator. This list +details the changes, and has methods of resolving the differences.

+
    +
  • JSE 5.0 or higher is required for Ibator
  • +
  • Ibator does not contain the "legacy" code generators from Abator. You must + choose "Ibatis2Java2" or "Ibatis2Java5" as a target runtime - and code generated from + Ibator is compatible with iBATIS version 2.2.0 or higher only. If you are + using an earlier version of iBATIS - upgrade! If you are not able to upgrade, + then you must continue to use Abator.
  • +
  • The classloading strategy in Ibator is changed from Abator. In all cases, we now recommend + specifying the classpath external to Ibator and we further recommend that you do not use + the <classPathEntry> element. You may specify classpath entries + if you feel you must, but those entries will only be used when loading JDBC drivers + of Java model root classes. If you write a custom extension to Ibator, or a plugin, + you must specify that classpath entry external to Ibator.
  • +
  • The API for extending Ibator is significantly changed from Abator. + In most cases, implementations of the old Abator interfaces should + be converted to Ibator plugins. See the + Extending Ibator for more information.
  • +
  • The afterXXXGenerationHook methods have been removed from + all Ibator supplied implementations of the core interfaces. If you + were extending an Ibator supplied implementation to make use of these methods, + then you must migrate your code to an Ibator plugin.
  • +
  • The build has been significantly modified and now includes an Emma based + code coverage report.
  • +
  • Changes to the XML configuration file are required. See the + Migrating from Abator page for detailed + information
  • +
+ +

Version 1.1.0

+

Announcements

+
    +
  • The next release of Abator will require JRE 5.0 or higher.
  • +
  • Java2 is now the default generator set. This will cause different code to be + generated if you have not specified a generator set previously. To remedy this, + set the generator set to "Legacy".
  • +
+ +

New Generated Methods

+

Abator will generate these new methods:

+
+
countByExample
+
This method will return an integer representing the number of rows in a table + that match the given criteria.
+
updateByExample
+
This method will update all rows in a table that match a given criteria. This method is + available in the Java2 and Java5 generator sets only. There is also a "selective" version + of the method that only updates certain columns of a table (the selective version of this + method is probably the more useful version to use in most situations).
+
+ +

Bugs Fixed

+
    +
  • Fixed bug for corner case where a criteria class is created, but no criteria + are set.
  • +
  • Fixed a bug that caused the JavaModelGenerator's "trimStrings" property to fail
  • +
  • Fixed the XML file merger so that internal entities are preserved
  • +
  • Fixed the XML configuration parser so that external entities are handled properly
  • +
  • Fixed bug - incorrect datatype mapping for JDBC BIT datatype
  • +
  • Fixed bug where Abator generated incorrect properties for certain database columns + (for example, if the column name is I_NAME)
  • +
+ +

Miscellaneous Changes

+
    +
  • Added the ability to specify properties to ignore qualifiers and change runtime + table names in the generated SQL for a table. Primary use cases for this + support include: +
      +
    • Generating objects for a table that has a public synonym or alias
    • +
    • Generating objects for a table that exists in many schemas, and the + schema will be selected at runtime
    • +
    + See the <table> + reference page for more information, or the + Oracle reference page for an example.
  • +
  • Added support for delimiting SQL identifiers for the use cases where identifiers + contain spaces or SQL reserved words. + See the <table>, + <abatorContext>, + and <columnOverride> + reference pages for more information.
  • +
  • Added SYBASE dialect for generated keys. + See the <generatedKey> + reference page for more information.
  • +
  • Added DB2_MF (DB2 on Main Frames) dialect for generated keys. + See the <generatedKey> + reference page for more information.
  • +
  • Abator will now automatically escape identifiers that contain the $ or # characters + as these characters have special meaning in iBATIS configuration files.
  • +
  • Added a clear method to the generated example classes (in the Java2 and Java5 + generator sets only). This allows reuse of these classes.
  • +
  • Added the ability to specify that result maps should use column indexes rather + than column names in the result mappings. Primary use cases for this + support include: +
      +
    • When tables have columns whose name is only differentiated by + case (e.g. "first name" and "First Name")
    • +
    • When you want to make the selects as fast as possible (there is a slight + performance benefit when using column indexes)
    • +
    + See the <table> + reference page for more information.
  • +
  • Made the generated Example and Criteria classes extendable. Added some documentation + about how to extend these classes. See the + Extending the Example Classes + reference page for more information.
  • +
  • Made the legacy DAOs extendable.
  • +
  • Added the ability to provide a renaming rule for columns. This is for the + use case where columns have a common prefix that should be removed before + calculating the property name. See the + <columnRenamingRule> + reference page for more information.
  • +
  • Added support for persisting a configuration to XML - this to enable + a graphical editor in the future.
  • +
  • Add afterXXXGenerationHook() methods in all generators to enable adding + extra Java code or XML elements to any generated object. This will make + it easier to create customized generators.
  • +
  • API change to allow generating with selected contexts rather than + the entire config file.
  • +
  • API change to allow generating with selected tables rather than + the entire config file.
  • +
  • Exposed new support for selecting tables and/or contexts to the + command line and the Ant task - this has added an advanced syntax to the command + line for Abator. See the + Running Abator reference page for more information.
  • +
  • rootClass and rootInterface may now be specified for each table. + See the <table> + reference page for more information.
  • +
  • If a rootClass is specified for any table, Abator will now check in the + rootClass to see if a generated property already exists in the root class. If it does, + Abator will not generate the property. The <javaModelGenerator> element now + accepts a property to specify the classpath of the rootClass. See the + <javaModelGenerator> + reference page for more information. Thanks to Ashok Madhavan for the beginnings + of this code.
  • +
  • Allowed specifying a type (pre or post) for the generated key element. See the + <generatedKey> + reference page for more information.
  • +
  • Added a comment generator interface to enable generation of custom comments. + See the <commentGenerator> + reference page for more information.
  • +
+ +

Version 1.0.0

+

Generator Sets

+

A generator set is a set of +code generators (SQL Map Generator, Java Model Generator, DAO Generator, and Java Type Resolver). +Abator now ships three different generator sets. The generated code from these three +generator sets is slightly different, and the use of the generated objects is slightly +different too. The concepts are exactly the same. With the newer generator sets, the +"by example" methods have been vastly improved. It is now possible to generate +virtually any WHERE clause (including IN and BETWEEN predicates). Lastly, the new +generator sets generate much more concise code - the DAOs and SQL Maps are of +normal size, and there are no extraneous methods. The example class in the new generator +sets encapsulates all the function needed to generate dynamic queries.

+

The three generator sets shipped with Abator are as follows:

+
+
Legacy
+
This generator set generates code that is the same as previous versions of + Abator. There are some limitations with this generator set and we strongly + recommend that you choose one of the other sets. However, this set remains + the default for now. This generator set will likely be removed in a future + version of Abator.
+
Java2
+
This generator set generates code that is compatible with iBATIS versions 2.2.0 and + higher. With this generator set the "by example" methods are much more powerful + than in the legacy set. It is now possible to generate + virtually unlimited SQL WHERE clauses with Abator generated code (including "IN" + and "BETWEEN" clauses). This generator set will likely become the default set in a + future version of Abator.
+
Java5
+
This generator set has the same capabilities as the Java2 generator set with the + added feature of generating code that is JSE 5.0 compliant using parameterized + types and annotations.
+
+

Important: code generated with the Java2 or Java5 generator sets is not 100% +compatible with code generated with the Legacy set - especially in the use of the +"by example" methods. Also note that the "by example" methods in these generator sets rely +on iBATIS dynamic SQL support that is missing in iBATIS versions prior to version 2.2.0.

+

A generator set is selected with the generatorSet attribute of the +<abatorContext> element. See the +<abatorContext> reference page for +more information.

+ +

Use of the example classes is different with the different generator sets. See the +Example Class Usage page for more +information.

+ +

Model Types

+

A model type is used to give you more control over the types of domain objects +generated by Abator. Abator now supports three different types of domain models +as follows:

+
+
conditional
+
This model is similar to the hierarchical model except that a separate + class will not be generated if that separate class would only contain + one field. So if a table has only one primary key field, that field + will be merged into the base record class. This model type is the default. + Note that this model type may generate classes that are not 100% + with classes generated in previous versions of Abator.
+
flat
+
This model generates only one domain class for any table. The class + will hold all fields in the table.
+
hierarchical
+
This model is the same as the model shipped with the initial versions + of Abator. This model will generate a primary key class if the table has + a primary key, another class that holds any BLOB columns in the table, and + another class that holds the remaining fields. There is an appropriate + inheritance relationship between the classes.
+
+ +

Model types can be specified as a default for an entire context, and you may +override the default for each table in a context. See the +<abatorContext> reference page for +more information about setting the context default.. +See the <table> +reference page for more information about setting a model type for specific tables. +

+

Important: the default value is conditional - this is a non-backward compatible +change from previous versions of Abator.

+ +

updateByPrimaryKeySelective

+

This is a new mapped SQL statement, and new DAO method, that will only +update columns whose corresponding properties in the parameter class are non-null. +This can be used to update certain +columns in a record without needing to update the entire record. +

+

Important: any column that is mapped to a primitive type +will always be updated.

+ +

Miscellaneous Changes

+
    +
  • Added the ability to specify a table alias. This aids in reuse of generated + SQL map elements. See the <table> + reference page for more information.
  • +
  • Fixed the XML file merger so that extraneous blank lines at the end of the + file are removed.
  • +
  • Added the ability to specify a type handler for table columns. + See the <columnOverride> + reference page for more information.
  • +
  • Added the ability to specify the visibility of the DAO "by example" methods. + This allows you to make the methods private for internal use only. + See the <javaClientGenerator> + reference page for more information.
  • +
  • Added the ability to override the naming convention for DAO method names. + See the <javaClientGenerator> + reference page for more information.
  • +
  • Added the ability to specify wildcards for schema or tableName in a table + configuration. This will allow generation of many tables with a simple + XML configuration. + See the <table> + reference page for more information.
  • +
  • Added the ability to escape wildcard characters in schema or table names + if required by the driver. See the <table> + reference page for more information.
  • +
  • Added the ability to suppress JSE 5.0 type warning messages for non-parameterized + types if you are using the Legacy or Java2 generator sets in a JSE 5.0 environment. + See the <abatorContext> + reference page for more information. +
  • +
  • Added the ability to specify an external properties file for passing + parameters into an Abator configuration file (like the iBATIS properties + file). See the <properties> + reference page for more information. +
  • +
  • The Ant task now supports a "verbose" attribute. See the + Running Abator page for more information. +
  • +
  • The Ant task now supports a nested property set for passing values into + an Abator configuration file. See the + Running Abator page for more information. +
  • +
+ + \ No newline at end of file