Skip to content

zscgrhg/mybatis-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mybatis Generator Plugin

##1. Maven repository

<dependency>
    <groupId>com.tqlab.plugin</groupId>
    <artifactId>tqlab-mybatis-plugin</artifactId>
    <version>1.0.6</version>
</dependency>

##2. Plugin Activity Diagram

Mybatis Generator Plugin Activity Diagram

##3. Plugin Configuration Sample

	<build>
		<plugins>
			<plugin>
				<groupId>com.tqlab.plugin</groupId>
				<artifactId>tqlab-mybatis-plugin</artifactId>
				<version>1.0.6</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&amp;characterEncoding=UTF-8&amp;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>
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
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
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

##4. Sql Template File Sample


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

##5. Change log ###v 1.0.2

  1. bugfix hsqldb sql
  2. Add mysql support
  3. Add extra config (tableNames)

###v 1.0.3

  1. modify Java Code generate commment
  2. config commentGenerator property suppressDate false
  3. change @paramter expression to maven annotation

###v1.0.4

  1. bugfix 1.0.3. The v1.0.3 has a serious bug when release to maven centeral.

###v1.0.5

  1. Add mybatis sql template xml Scheam support.
  2. Add log4j support when generate Java Mapper.
  3. Add tableNames validate.
  4. Add jsqlpaser for SQL validation.
  5. Add tablePrefix config support.
  6. Add auto delete ...dao /...dataobject package files when set overwrite is ture.
  7. Delete unused code.

###v1.0.6

  1. bugfix mysql table generate code error when name is uppercase.
  2. bugfix table generate code error when the column's type is BLOB,BINARY or VARBINARY.
  3. Add dynamic script for annotation supported.
  4. Add parameter of Object type supported.

###v1.0.7

  1. update jsqlparser version to 0.8.9
  2. Add mybatis Options annotation supported.
  3. Add alias name config supported.
  4. Add specific driver supported.

About

Mybatis Generator Plugin Extension

Resources

Stars

Watchers

Forks

Packages

No packages published