<dependency>
<groupId>com.tqlab.plugin</groupId>
<artifactId>tqlab-mybatis-plugin</artifactId>
<version>1.0.9</version>
</dependency>
Single database:
<build>
<plugins>
<plugin>
<groupId>com.tqlab.plugin</groupId>
<artifactId>tqlab-mybatis-plugin</artifactId>
<version>1.0.8</version>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<phase>deploy</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.basedir}</outputDirectory>
<!-- db config -->
<jdbcURL>jdbc:mysql://localhost/testdb?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull</jdbcURL>
<jdbcUserId>user</jdbcUserId>
<jdbcPassword>password</jdbcPassword>
<database>testdb</database>
<dbName>mysql</dbName>
<!-- db config end -->
<!-- <sqlScript>${project.basedir}/src/main/resources/mysql.sql</sqlScript> -->
<packages>com.taobao.bns.dal</packages>
<sqlTemplatePath>${project.basedir}/src/main/resources/sqltemplate/</sqlTemplatePath>
<overwrite>true</overwrite>
<useCache>false</useCache>
<generateJdbcConfig>false</generateJdbcConfig>
<generateSpringConfig>true</generateSpringConfig>
</configuration>
</plugin>
</plugins>
</build>
Multi-database:
<build>
<plugins>
<plugin>
<groupId>com.tqlab.plugin</groupId>
<artifactId>tqlab-mybatis-plugin</artifactId>
<version>1.0.8</version>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<phase>deploy</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.basedir}</outputDirectory>
<databaseConfig>
<config>
<!-- db config -->
<jdbcURL>jdbc:mysql://localhost/testdb1?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull</jdbcURL>
<jdbcUserId>user</jdbcUserId>
<jdbcPassword>password</jdbcPassword>
<database>testdb1</database>
<dbName>mysql</dbName>
<!-- db config end -->
<!-- <sqlScript>${project.basedir}/src/main/resources/mysql.sql</sqlScript> -->
<packages>com.taobao.bns.dal</packages>
<sqlTemplatePath>${project.basedir}/src/main/resources/sqltemplate/</sqlTemplatePath>
<generateJdbcConfig>false</generateJdbcConfig>
<generateSpringConfig>true</generateSpringConfig>
<overwrite>true</overwrite>
</config>
<config>
<!-- db config -->
<jdbcURL>jdbc:mysql://localhost/testdb2?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull</jdbcURL>
<jdbcUserId>user</jdbcUserId>
<jdbcPassword>password</jdbcPassword>
<database>testdb2</database>
<dbName>mysql</dbName>
<!-- db config end -->
<!-- <sqlScript>${project.basedir}/src/main/resources/mysql.sql</sqlScript> -->
<packages>com.taobao.bns.dal</packages>
<sqlTemplatePath>${project.basedir}/src/main/resources/sqltemplate/</sqlTemplatePath>
<generateJdbcConfig>false</generateJdbcConfig>
<generateSpringConfig>true</generateSpringConfig>
<useCache>false</useCache>
</config>
</databaseConfig>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
</build>
Attribute | Description | Default value | Required |
---|---|---|---|
outputDirectory | Oupput directory | ${project.build.directory}/generated-sources/mybatis-generator | |
sqlScript | Location of a SQL script file to run before generating code. | false | |
jdbcURL | Database url | true | |
jdbcUserId | Database user | false | |
jdbcPassword | Database password | false | |
tableNames | Comma delimited list of table names to generate | all tables of current database | false |
tablePrefix | For example, table name: wp_xxxx, the word 'wp' is the table prefix | false | |
doSuffix | For example, DO, the object name is xxxDO | false | |
doRootClass | Data Object super class | false | |
database | Database | true | |
dbName | Database name, mysql, hsqldb etc. | true | |
packages | Java package name, com.tqlab.test etc. | true | |
overwrite | Overwrite the exist code, config file or not. | false | false |
sqlTemplatePath | SqlMapper template path | true | |
useCache | Use cache or not. | false | false |
providerEnable | Generate default SQL Provider or not. | true | false |
selectKeyEnable | Generate @SelectKey or not. | true | false |
generateSpringConfig | Generate spring osgi xml config file or not. | false | false |
generateOsgiConfig | Generate spring osgi xml config file or not. | false | false |
properties | extra config | false |
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://schema.tqlab.com/mybatis"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schema.tqlab.com/mybatis http://schema.tqlab.com/mybatis/tqlab-mybatis-plugin.xsd"
name="star">
<operation id="deleteById">
<sql>
<![CDATA[
delete from star where id=#{id,jdbcType=INTEGER};
]]>
</sql>
</operation>
<operation id="count" resultType="java.lang.Integer">
<sql>
<![CDATA[
select count(*) from star;
]]>
</sql>
</operation>
<operation id="sum" resultType="java.lang.Integer">
<sql>
<![CDATA[
select sum(id) from star;
]]>
</sql>
</operation>
<operation id="selectAll" many="true">
<sql>
<![CDATA[
select * from star;
]]>
</sql>
</operation>
<operation id="selectById" many="false">
<sql>
<![CDATA[
select * from star where id=#{id,jdbcType=INTEGER};
]]>
</sql>
</operation>
<operation id="selectWithPagination">
<comment>
demo
</comment>
<sql>
<![CDATA[
select limit #{start,jdbcType=INTEGER} #{size,jdbcType=INTEGER} * from star;
]]>
</sql>
</operation>
<operation id="selectComplex1" many="true">
<result objectName="StarMovies">
<property cloumn="id" javaProperty="id" javaType="java.lang.Integer" />
<property cloumn="firstname" javaProperty="firstname"
javaType="java.lang.String" />
<property cloumn="lastname" javaProperty="lastname"
javaType="java.lang.String" />
<property cloumn="movieid" javaProperty="movieid" javaType="java.lang.Integer" />
<property cloumn="title" javaProperty="title" javaType="java.lang.String" />
</result>
<sql>
<![CDATA[
select a.*, b.* from star a, movies b where a.id = b.starid
]]>
</sql>
</operation>
<operation id="selectComplex2" many="true">
<result objectName="StarMovies2">
<property cloumn="star_id" javaProperty="id" javaType="java.lang.Integer" />
<property cloumn="name" javaProperty="firstname" javaType="java.lang.String" />
<property cloumn="lastname" javaProperty="lastname"
javaType="java.lang.String" />
<property cloumn="movieid" javaProperty="movieid" javaType="java.lang.Integer" />
<property cloumn="title" javaProperty="title" javaType="java.lang.String" />
</result>
<sql>
<![CDATA[
select a.id as star_id, a.firstname as name, a.lastname,
b.movieid, b.title from star a, movies b
where a.id = b.starid
]]>
</sql>
</operation>
</table>
More sample: https://github.com/tqlab/mybatis-plugin/blob/master/demo/src/main/resources/sqltemplate/hsqldb/table.star.xml
- bugfix hsqldb sql
- Add mysql support
- Add extra config (tableNames)
- modify Java Code generate commment
- config commentGenerator property suppressDate false
- change @paramter expression to maven annotation
- bugfix 1.0.3. The v1.0.3 has a serious bug when release to maven centeral.
- Add mybatis sql template xml Scheam support.
- Add log4j support when generate Java Mapper.
- Add tableNames validate.
- Add jsqlpaser for SQL validation.
- Add tablePrefix config support.
- Add auto delete ...dao /...dataobject package files when set overwrite is ture.
- Delete unused code.
- bugfix mysql table generate code error when name is uppercase.
- bugfix table generate code error when the column's type is BLOB,BINARY or VARBINARY.
- Add dynamic script for annotation supported.
- Add parameter of Object type supported.
- update jsqlparser version to 0.8.9
- Add mybatis Options annotation supported.
- Add alias name config supported.
- Add specific driver supported.
- update jsqlparser version to 1.2
- Add @SelectKey supported
- Add Provider annotation config (providerEnable default true).
- bugfix generatedKey
- update mybatis to 3.5.0
- update jsqlparser version to 1.4
- Add connectionFactory plugin supported.
- Add selectKeyEnable config supported.