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>
The supplied plugins are all 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.
This plugin adds a <cache> element to generated SQL maps. This plugin is for MyBatis3 targeted runtimes only.
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.
Any property can be overridden by specifying the property on a <table> element.
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.
This plugin adds equals
and hashCode
methods to the
Java model objects generated by MBG.
The equals
method generated by this class is correct in most
cases, but will probably NOT be correct if you have specified a rootClass -
because our equals method only checks the fields it knows about.
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:
Note: targetPackage
and targetProject
follow
the same rules as the targetPackage
and targetProject
values on the sqlMapGenerator configuration element.
This plugin demonstrates usage of the initialized
method
by renaming the generated example classes generated by MBG.
This plugin accepts two properties:
For example, to rename the generated example classes from xxxExample to xxxCriteria, specify Example$ for searchString and Criteria for replaceString
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.
This plugin adds the marker interface java.io.Serializable
to the
Java model objects generated by MBG. 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:
IsSerializable
interface to the model
objects. The default is false.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.This plugin generates a skeleton SqlMapConfig.xml file that contains references to the SqlMap.xml files generated by MBG. This file can be used to configure iBATIS 2.x environments.
This plugin accepts three properties:
Note: targetPackage
and targetProject
follow
the same rules as the targetPackage
and targetProject
values on the sqlMapGenerator configuration element.
This plugin adds toString()
methods to the generated
model classes.
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>