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>

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.

org.mybatis.generator.plugins.CaseInsensitiveLikePlugin

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 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.

org.mybatis.generator.plugins.MapperConfigPlugin

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 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 will add an override 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 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.

org.mybatis.generator.plugins.SqlMapConfigPlugin

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:

  • fileName (optional) the name of the generated file. this defaults to "SqlMapConfig.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.