Code Monkey home page Code Monkey logo

mybatis-generator-plugins's Introduction

GitHub license Build Status Stories in Ready codecov.io Maven Central

MyBatis Generator Plugins

Set of plugins for the mybatis-generator to further tweak the generated code.

CreateSubPackagePlugin

Powerful plugin that will rename the generated model, mappers and examples by moving them in a sub-package and/or append a suffix. This is intended to keep generated code apart from the final classes to allow the geneator plugin to overwrite them every time.

e.g.: some.package.Actor will now be generated as some.package.sub.ActorSuffix and will be abstract. some.package.ActorMapper will now be generated as some.package.sub.ActorMapperSuffix but methods will still expect and object of type some.package.Actor (to be created manually).

There are 6 optional parameters to set:

  • modelSubPackage: The sub package to create for model classes.
  • modelClassSuffix: The suffix to add to model classes.
  • mapperSubPackage: The sub package to create for mapper interfaces.
  • mapperClassSuffix: The suffix to add to mapper interfaces.
  • exampleSubPackage: The sub package to create for example classes.
  • exampleClassSuffix: The suffix to add to example classes.

e.g.:

<plugin type="com.github.dcendents.mybatis.generator.plugin.subpackage.CreateSubPackagePlugin">
	<property name="modelSubPackage" value="gen" />
	<property name="modelClassSuffix" value="Gen" />
	<property name="mapperSubPackage" value="gen" />
	<property name="mapperClassSuffix" value="Gen" />
	<property name="exampleSubPackage" value="filter" />
</plugin>

RenameExampleClassAndMethodsPlugin

Plugin that will rename the example classes and parameters to give them a more suitable name for a production environment. Also this plugin will fix the update statements and remove the id column(s). There are 4 mandatory parameters to set:

  • classMethodSearchString: The string to search in class names.
  • classMethodReplaceString: The replace value.
  • parameterSearchString: The string to search for parameter names.
  • parameterReplaceString: The replace value.

e.g.:

<plugin type="com.github.dcendents.mybatis.generator.plugin.rename.RenameExampleClassAndMethodsPlugin">
	<property name="classMethodSearchString" value="Example" />
	<property name="classMethodReplaceString" value="Filter" />
	<property name="parameterSearchString" value="example" />
	<property name="parameterReplaceString" value="filter" />
</plugin>

AddClassAnnotationsPlugin

Plugin that will add the specified annotation to every generated class. There are 2 mandatory parameters to set:

  • annotationClass: The class of the annotation, this will be added as an import statement.
  • annotationString: The literal string that will be added, complete will all values

If you need to add multiple annotations, configure this plugin many times, one per annotation to add.

e.g.:

<plugin type="com.github.dcendents.mybatis.generator.plugin.annotation.AddClassAnnotationsPlugin">
	<property name="annotationClass" value="lombok.ToString" />
	<property name="annotationString" value="@ToString(callSuper = true)" />
</plugin>
<plugin type="com.github.dcendents.mybatis.generator.plugin.annotation.AddClassAnnotationsPlugin">
	<property name="annotationClass" value="lombok.EqualsAndHashCode" />
	<property name="annotationString" value="@EqualsAndHashCode(callSuper = true)" />
</plugin>

AlterModelPlugin

A simple plugin to modify the generated model. Currently it can add interfaces to the specified generated model class. There are 2 mandatory parameters to set:

  • fullyQualifiedTableName: The name of the database table including the schema.
  • addInterfaces: A coma delimited list of interfaces to add to the model class implementations.

e.g.:

<plugin type="com.github.dcendents.mybatis.generator.plugin.model.AlterModelPlugin">
	<property name="fullyQualifiedTableName" value="public.car" />
	<property name="addInterfaces" value="com.github.dcendents.mybatis.jaxws.db.model.Vehicle" />
</plugin>
<plugin type="com.github.dcendents.mybatis.generator.plugin.model.AlterModelPlugin">
	<property name="fullyQualifiedTableName" value="public.chopper" />
	<property name="addInterfaces" value="com.github.dcendents.mybatis.jaxws.db.model.Vehicle" />
</plugin>

WrapObjectPlugin

Plugin that can be used to make a generated class wrap another java bean. For each property to wrap, the field will not be generated and the getter/setter will simply redirect to the wrapped java bean methods instead. This strategy can be used when you need to persist some third party objects but still want the flexibility to add new properties (like a database id). This pattern is more flexible than trying to extend the class. There are 2 mandatory and 3 optional parameters to set:

  • fullyQualifiedTableName: The name of the database table including the schema.
  • objectClass: The class of the object to be wrapped.
  • objectFieldName: The name of the field to add, will default to the class name starting with a lower case.
  • includes: A coma separated list of fields to delegate to the wrapped object, everything else will be excluded. If left blank all fields are included.
  • excludes: A coma separated list of fields to exclude.

The plugin need to be added for each table as needed.

e.g.:

<plugin type="com.github.dcendents.mybatis.generator.plugin.wrap.WrapObjectPlugin">
	<property name="fullyQualifiedTableName" value="public.film" />
	<property name="objectClass" value="com.github.dcendents.mybatis.jaxws.api.Film" />
	<property name="excludes" value="language" />
</plugin>
<plugin type="com.github.dcendents.mybatis.generator.plugin.wrap.WrapObjectPlugin">
	<property name="fullyQualifiedTableName" value="public.actor" />
	<property name="objectClass" value="com.github.dcendents.mybatis.jaxws.api.Actor" />
</plugin>

AlterResultMapPlugin

A simple plugin to modify the generated client to use a different ResultMap. There are 2 mandatory parameters to set:

  • fullyQualifiedTableName: The name of the database table including the schema.
  • resultMapId: The id of the result map to be used.

e.g.:

<plugin type="com.github.dcendents.mybatis.generator.plugin.client.AlterResultMapPlugin">
	<property name="fullyQualifiedTableName" value="public.film" />
	<property name="resultMapId" value="FullResultMap" />
</plugin>

Demo

See the following project for a demo of most of these plugins: https://github.com/dcendents/mybatis-jaxws

Build Metrics

Build Status codecov.io Dependency Status codecov.io Throughput Graph

License

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.

mybatis-generator-plugins's People

Contributors

dcendents avatar

Watchers

zhaojc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.