eclipse maven 中使用 mybatis-generator

1. pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>org.study</groupId>
	<artifactId>MybatisGenerator</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>MybatisGenerator Maven Webapp</name>
	<url>http://maven.apache.org</url>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
			<scope>test</scope>
		</dependency>
		 <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.2.7</version>
        </dependency>
	</dependencies>
	<build>
		<finalName>maven</finalName>
		<plugins>
			<plugin>
				<groupId>org.mybatis.generator</groupId>
				<artifactId>mybatis-generator-maven-plugin</artifactId>
				<version>1.3.1</version>
				<configuration>
					<configurationFile>src/main/resources/mybatis-generator.xml</configurationFile>
					<overwrite>true</overwrite>
				</configuration>
				<dependencies>
					<dependency>
						<groupId>mysql</groupId>
						<artifactId>mysql-connector-java</artifactId>
						<version>5.1.26</version>
					</dependency>
				</dependencies>
			</plugin>
		</plugins>
	</build>
</project>
2. mybatis-generator.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="E:\repo\mysql\mysql-connector-java\5.1.26\mysql-connector-java-5.1.26.jar" /> -->
	
	<context id="generatorTables" targetRuntime="MyBatis3">
		<plugin type="org.mybatis.generator.plugins.MapperConfigPlugin">
			<property name="fileName" value="mybatis-config.xml" />
			<property name="targetPackage" value="/" />
			<property name="targetProject" value="src/main/resources" />
		</plugin>

		<!-- 此處是將 Example 改名爲 Criteria 想改成什麼都行 -->
		<plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin">
			<property name="searchString" value="Example" />
			<property name="replaceString" value="Criteria" />
		</plugin>

		<plugin type="org.mybatis.generator.plugins.SerializablePlugin" />

		<!-- commentGenerator 去除自動生成的註釋 -->
		<commentGenerator>
			<property name="suppressAllComments" value="true" />
			<property name="suppressDate" value="true" />
		</commentGenerator>

		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://127.0.0.1:3306/test" userId="root"
			password="test">
		</jdbcConnection>

		<!-- 默認false,把JDBC DECIMAL 和 NUMERIC 類型解析爲 Integer true, 把 JDBC DECIMAL 和 NUMERIC 類型解析爲java.math.BigDecimal -->
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>

		<!-- javaModelGenerator是模型的生成信息,這裏將指定這些Java model類的生成路徑; -->
		<javaModelGenerator targetPackage="org.study.model"
			targetProject="src/main/java">
			<property name="enableSubPackages" value="true" />
			<property name="trimStrings" value="true" />
		</javaModelGenerator>

		<!-- sqlMapGenerator是mybatis 的sqlMapper XML文件的生成信息,包括生成路徑等; 先生成xml,在生成java -->
		<sqlMapGenerator targetPackage="org.study.dao"
			targetProject="src/main/resources">
			<property name="enableSubPackages" value="true" />
		</sqlMapGenerator>

		<!-- javaClientGenerator是應用接口的生成信息; -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="org.study.dao" targetProject="src/main/java">
			<property name="enableSubPackages" value="true" />
		</javaClientGenerator>

		<!-- table是用戶指定的被生成相關信息的表,它必須在指定的jdbc連接中已經被建立。?是否可以多個 -->

		<table tableName="cust_info" domainObjectName="CustInfo"
			enableCountByExample="false" enableUpdateByExample="false"
			enableDeleteByExample="false" enableSelectByExample="false"
			selectByExampleQueryId="false"></table>
		<!-- <table tableName="app_bind_status" domainObjectName="AppBindStatus" 
			enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" 
			enableSelectByExample="false" selectByExampleQueryId="false"></table> -->

	</context>
</generatorConfiguration> 
<!-- mybatis-generator:generate 執行命令-->
3. 工程右鍵 Debug As -> maven build... -> mybatis-generator:generate

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章