MyBatis Generator Quick Start Guide
To get up and running quickly with MyBatis Generator (MBG), follow these steps:
- Create and fill out a configuration file appropriately.
At a minimum, you must specify:
- A <jdbcConnection> element to specify how to connect to
the target database
- A <javaModelGenerator> element to specify target package
and target project for generated Java model objects
- A <sqlMapGenerator> element to specify target package
and target project for generated SQL map files
- (Optionally) A <javaClientGenerator> element to specify target package
and target project for generated client interfaces and classes (you may
omit the <javaClientGenerator> element if you don't wish to generate Java client code)
- At least one database <table> element
See the XML Configuration File Reference
page for an example of a configuration file.
- Save the file in some convenient location (like \temp\generatorConfig.xml)
- Run MBG from the command line with a command like this:
java -jar mybatis-generator-core-x.x.x.jar -configfile \temp\generatorConfig.xml -overwrite
This will tell MBG to run using your configuration file. It will also tell MBG
to overwrite any existing Java files with the same name. If you want to save any existing
Java files, then omit the -overwrite parameter. If there is a conflict, MBG
will save the newly generated file with a unique name (e.g. MyClass.java.1).
- After running MBG, you will need to create or modify the standard MyBatis or iBATIS
configuration files to make use of your newly generated code. See the
Tasks After Running MyBatis Generator page for more
information.
Important: Generated code for iBATIS2 requires that statement namespaces are enabled
in your iBATIS configuration. See the Tasks After Running MyBatis Generator
page for more information.