效果图:

注意:generatorConfig.xml的目录一定要正确

eclipse_mybatis_maven_oracle逆向工程_xml

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/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>asyf</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>demo</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

</project>

generatorConfig.xml

注意:下载ojdbc6-12.1.0.1-atlassian-hosted.jar包,下载jar包存放的目录一定要正确。

<?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>
<!-- 数据库驱动包位置 -->
<!-- mysql -->
<!-- <classPathEntry location="D:\jar\mysql-connector-java-5.1.18.jar" /> -->

<!-- oracle 下载ojdbc6-12.1.0.1-atlassian-hosted.jar放在本地磁盘 -->
<classPathEntry location="D:\jar\ojdbc6-12.1.0.1-atlassian-hosted.jar" />

<context id="testTables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--oracle数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="oracle.jdbc.OracleDriver"
connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:oradb" userId="asyf"
password="123">
</jdbcConnection>


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

<!-- targetProject:生成model类的位置,重要!! -->
<javaModelGenerator targetPackage="asyf.demo"
targetProject=".\src\main\java\">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>

<!-- targetProject:mapper映射xml文件生成的位置,重要!! -->
<sqlMapGenerator targetPackage="asyf.demo"
targetProject=".\src\main\java\">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>

<!-- targetPackage:mapper接口生成的位置,重要!! -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="asyf.demo" targetProject=".\src\main\java\">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>

<!-- 指定数据库表,要生成哪些表,就写哪些表,要和数据库中对应,不能写错! -->
<table tableName="T_GS_ES_DICTIONARIES" domainObjectName="TestModel"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"></table>
</context>
</generatorConfiguration>

项目右键->run as->maven build...,Goals:中输入mybatis-generator:generate

eclipse_mybatis_maven_oracle逆向工程_maven_02

点击下面的 apply 再run

eclipse_mybatis_maven_oracle逆向工程_java_03

生成完成。顶部有效果图。