MyBatis Generator Introduction
MyBatis Generator (MBG) is a MyBatis code generator MyBatis and IBATIS. He can generate code for each version of MyBatis, and Ibatis 2.2.0 later code. He can introspect the database's tables (or tables) and then generate the underlying objects that can be used to access (multiple) tables. This makes it unnecessary to create objects and configuration files when interacting with database tables. MBG solves some simple crud (insert, query, UPDATE, DELETE) operations that have the greatest impact on database operations. You still need to write SQL and objects to federated queries and stored procedures.
MyBatis Generator will generate:
- Java POJO that match the table structure, which may include:
- A class that matches the primary key of the table (if there is a primary key [note: Only the federated primary Key will be])
- A class that contains a non-primary key field (except for BLOB fields [Note: This is included in the single-field master key])
- A class that contains a BLOB field (if the table contains a BLOB field)
- A class that allows dynamic querying, updating, and deletion [Note: Refers to example query]
There is an appropriate inheritance relationship between these classes. Note that you can configure the generator to generate hierarchies of different types of POJO. For example, if you prefer, you might choose to generate a separate entity object for each table.
- Mybatis/ibatis compatible SQL map XML file. MBG generates SQL for a simple CRUD operation for each table in the configuration. The generated SQL statements include:
- Insert (insertion)
- Update by primary key (updating records based on primary key)
- Update by example (record updated by condition)
- Delete by primary key (deleting records based on primary key)
- Delete by example (deleting records based on criteria)
- Select by primary key (query records based on primary key)
- Select by example (query recordsets based on criteria)
- Count by example (total number of records based on criteria)
Depending on the structure of the table, the resulting statements will vary (for example, if there is no primary key in the table, then MBG will not generate the update by primary key method).
- The Java client class uses the above objects appropriately and is optional when generating Java client classes. MBG will generate the following client class for MyBatis 3.x:
- A mapper interface class that can be used with MyBatis 3.x
MBG will generate the following client class for Ibatis 2.x:
- A DAO class that conforms to the Spring framework.
- Use only DAO with the Ibatis SQL mapping API. This DAO can be generated in the following two ways: Provides sqlmapclient by constructing a method or setter injection.
- Ibatis DAO Framework Compliant DAO (Ibatis optional part of this framework is obsolete and we recommend that you use the Spring framework instead).
MyBatis Generator can work well in an iterative development environment as an ant task or maven plugin in a continuous build environment. Here are some important things to keep in mind when running MBG:
- MBG automatically merges XML that already exists and has the same name as the newly generated file. MBG does not overwrite the modifications that you have made to the generated XML. You can run repeatedly without worrying about losing your customized changes. MBG will replace all the XML elements that were generated in the previous run.
- MBG does not merge Java files, he can overwrite existing files or save newly generated files for a different unique name. You can merge these changes manually. When you use the Eclipse plugin, MBG can automatically merge Java files.
Dependent items
MBG relies on JRE and requires JRE6.0 or later. In addition, there is a JDBC driver that inherits the DatabaseMetaData interface. In particular, getcolumns and Getprimarykeys two methods are required.
Support
Support for MyBatis generator is provided through the MyBatis user mailing list. You can subscribe to or view the code for your mailing list via Google:
Http://groups.google.com/group/mybatis-user
If you think you have found a bug, please ask in the user list before you create a new issue. If you find a bug, or have a new feature requirement, you can open a new issue on GitHub:
Https://github.com/mybatis/generator/issues
Translator
Translator level is limited, if you find the translation is not fluent in the place, you can create issue at the following address:
Http://git.oschina.net/free/mybatis-generator-core/issues
MyBatis Generator Introduction