🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# MyBatis Generator新增功能 ## Version 1.3.3 ### 公告 * MyBatis Generator 需要 JRE 1.6 或更高版本的支持 ### 改进 * 从 MyBatis 3.2 开始使用了新的 SQL 生成器类。 如果您必须在 MyBatis 旧版本上运行,在您的 < JavaClientGenerator > 配置上设置属性"useLegacyBuilder"为"true"。 * Issue #11 - maven插件现在会输出到maven日志 (thanks to Paul Krause) * Issue #4 - 如果任何列将解析为一个 Java 保留字,生成器现在会抛出一个警告 ### Bugs 修复 * Fixed issue #648 - Missing imports when using constructor based models * Issues #10 - EqualsHashCodePlugin now uses the java.util.Arrays methods for array attributes. ## Version 1.3.2 ### Bugs 修复 * 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 ### 改进 * 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](reference/plugins.html) * 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 修复 * 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 ### 改进 * 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: * The `targetRuntime` attribute of [<context>](configreference/context.html) element is **MyBatis3** * The `type` attribute of [<javaClientGenerator>](configreference/javaClientGenerator.html) element is **ANNOTATEDMAPPER** * 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: * The `targetRuntime` attribute of [<context>](configreference/context.html) element is **MyBatis3** * The `type` attribute of [<javaClientGenerator>](configreference/javaClientGenerator.html) element is **MIXEDMAPPER** * Add support for JDBC types NCHAR, NCLOB, NVARCHAR to match MyBatis3. * Added support for "useGeneratedKeys" in MyBatis3\. See [<generatedKey>](configreference/generatedKey.html) for details. * Added support for immutable objects and constructor based result maps in MyBatis3\. See [<table>](configreference/table.html) and/or [<javaModelGenerator>](configreference/javaModelGenerator.html) 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>](configreference/commentGenerator.html) for details. ## Version 1.3.0 1. Moved to mybatis.org, renamed MyBatis Generator 2. 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. 3. Configuration settings for MyBatis 3 are as follows: 1. The `targetRuntime` attribute of [<context>](configreference/context.html) element must be changed to **MyBatis3** 2. The `type` attribute of [<javaClientGenerator>](configreference/javaClientGenerator.html) element must be changed to **XMLMAPPER** 4. 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. ## 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()`. **重要提示:** 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>](configreference/sqlMapGenerator.html) configuration. * Ibator is now built with Maven and includes a Maven plugin ### Bugs 修复 * 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) ### 改进 * 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>](configreference/ibatorContext.html) 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](running.html) page for more information. * Added logging statements for use in debug. See the [Logging](reference/logging.html) page for more information. * Added new example plugin to demonstrate adding case insensitive LIKE support to generated Example classes. See the [<ibatorPlugin>](configreference/ibatorPlugin.html) page for more information. * Added "delimitAllColumns" attribute to table configurations. This supports databases like PosgreSQL that are case sensitive for identifiers. See the [<table>](configreference/table.html) page for more information. * Added a page explaining how to deal with case sensitivity in PostgreSQL. See the [PostgreSQL](usage/postgresql.html) page for more information. * IBATIS-586 - Added the ability to specify nested property elements on columnOverrides. See the [<columnOverride>](configreference/columnOverride.html) 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>](configreference/generatedKey.html) * 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 the IbatorObjectFactory so it will find internal classes from the context classloader. * Fixed IBATIS-565 - ill formed comment in the SqlMapConfigPlugin ### 改进 * 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](migratingFromAbator.html) page for detailed information about changes needed to existing Abator configuration files. ### Bugs 修复 * 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 ### 改进 * 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>](configreference/ibatorPlugin.html) 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>](configreference/table.html) 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](reference/extending.html) 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](migratingFromAbator.html) 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 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 runtimeSee the [<table>](configreference/table.html) reference page for more information, or the [Oracle](usage/oracle.html) 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>](configreference/table.html), [<abatorContext>](configreference/abatorContext.html), and [<columnOverride>](configreference/columnOverride.html) reference pages for more information. * Added SYBASE dialect for generated keys. See the [<generatedKey>](configreference/generatedKey.html) reference page for more information. * Added DB2_MF (DB2 on Main Frames) dialect for generated keys. See the [<generatedKey>](configreference/generatedKey.html) 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>](configreference/table.html) 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](generatedobjects/extendingExampleClass.html) 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>](configreference/columnRenamingRule.html) 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](running.html) reference page for more information. * `rootClass` and `rootInterface` may now be specified for each table. See the [<table>](configreference/table.html) 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>](configreference/javaModelGenerator.html) 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>](configreference/generatedKey.html) reference page for more information. * Added a comment generator interface to enable generation of custom comments. See the [<commentGenerator>](configreference/commentGenerator.html) 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. **重要:** 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>](configreference/abatorContext.html) reference page for more information. Use of the example classes is different with the different generator sets. See the [Example Class Usage](generatedobjects/exampleClassUsage.html) 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>](configreference/abatorContext.html) reference page for more information about setting the context default.. See the [<table>](configreference/table.html) reference page for more information about setting a model type for specific tables. **重要:** 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. **重要:** 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>](configreference/table.html) 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>](configreference/columnOverride.html) 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>](configreference/javaClientGenerator.html) reference page for more information. * Added the ability to override the naming convention for DAO method names. See the [<javaClientGenerator>](configreference/javaClientGenerator.html) 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>](configreference/table.html) 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>](configreference/table.html) 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>](configreference/abatorContext.html) 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>](configreference/properties.html) reference page for more information. * The Ant task now supports a "verbose" attribute. See the [Running Abator](running.html) 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](running.html) page for more information.