运行 MyBatis Generator 自动生成代码 - maven

1.在pom.xml文件中build标签目录中加入

<plugins>
	<plugin>
		<groupId>org.mybatis.generator</groupId>
		<artifactId>mybatis-generator-maven-plugin</artifactId>
		<version>1.3.2</version>
		<configuration>
			<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
			<verbose>true</verbose>
			<overwrite>false</overwrite>
		</configuration>
		<!-- <executions>
			<execution>
				<id>Generate MyBatis Artifacts</id>
				<goals>
					<goal>generate</goal>
				</goals>
			</execution>
		</executions> -->
		<dependencies>
			<dependency>
				<groupId>org.mybatis.generator</groupId>
				<artifactId>mybatis-generator-core</artifactId>
				<version>1.3.2</version>
			</dependency>
		</dependencies>
	</plugin>
</plugins>

2.配置generatorConfig.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
	<classPathEntry location="/Users/hanweisong/Documents/workspace/maven/repository/mysql/mysql-connector-java/5.1.36/mysql-connector-java-5.1.36.jar" />
	<context id="my" targetRuntime="MyBatis3">
		<commentGenerator>
			<property name="suppressDate" value="false" />
			<property name="suppressAllComments" value="true" />
		</commentGenerator>

		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/foxeye?useUnicode=true&amp;characterEncoding=utf8&amp;zeroDateTimeBehavior=convertToNull&amp;noAccessToProcedureBodies=true"
			userId="root" password="" />

		<javaModelGenerator targetPackage="com.foxeye.model"
			targetProject="/Users/hws/Documents/workspace/workspace/jolopay2.0/foxeye-webapp/foxeye-webapp/src/main/java">
			<property name="enableSubPackages" value="true" />
		</javaModelGenerator>

		<sqlMapGenerator targetPackage="mappers"
			targetProject="/Users/hws/Documents/workspace/workspace/jolopay2.0/foxeye-webapp/foxeye-webapp/src/main/resources">
			<property name="enableSubPackages" value="true" />
		</sqlMapGenerator>

		<javaClientGenerator targetPackage="com.foxeye.manager"
			targetProject="/Users/hws/Documents/workspace/workspace/jolopay2.0/foxeye-webapp/foxeye-webapp/src/main/java"
			type="XMLMAPPER">
			<property name="enableSubPackages" value="true" />
		</javaClientGenerator>

		<table tableName="tbl_user_" domainObjectName="User"
			enableCountByExample="false" enableUpdateByExample="false"
			enableDeleteByExample="false" enableSelectByExample="false"
			selectByExampleQueryId="false">
		</table>
	</context>
</generatorConfiguration>

3. run as  maven generate-source 命令

4. 刷新工程 可看到 modell类 mapper类 和mapper.xml文件已经生成


参考地址:http://mbg.cndocs.tk/running/runningWithMaven.html


你可能感兴趣的:(mybatis,自动生成代码)