为了更加清晰的知道这个工具的构成,新建一个maven干净的项目。
next
后,填上自己的artifactId
和groupId
,然后next
、finish
。OK,一个空项目就新建成功了。
添加依赖:
<dependencies>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>5.1.32version>
dependency>
<dependency>
<groupId>org.mybatis.generatorgroupId>
<artifactId>mybatis-generator-coreartifactId>
<version>1.3.6version>
dependency>
dependencies>
添加插件:
<build>
<finalName>taotao-code-generatorfinalName>
<plugins>
<plugin>
<groupId>org.mybatis.generatorgroupId>
<artifactId>mybatis-generator-maven-pluginartifactId>
<version>1.3.2version>
<configuration>
<configurationFile>F:\project-java\taotao-code-generate\src\main\resources\generator\generatorConfig.xmlconfigurationFile>
<verbose>trueverbose>
<overwrite>trueoverwrite>
configuration>
plugin>
plugins>
build>
为了避免错误,这里的configurationFile
,我用的时绝对路径,即是generatorConfig.xml
配置文件的位置。
由于上面的插件配置中,我用的是绝对路径,所以这里,这个文件,你可以建在任意的目录下,不多一般新建在resources
目录下就行了。
<generatorConfiguration>
<classPathEntry
location="D:\programs\apache-maven-3.5.2\my-repository\repo\mysql\mysql-connector-java\5.1.32\mysql-connector-java-5.1.32.jar" />
<context id="default" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
commentGenerator>
<jdbcConnection
driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/taotao"
userId="root"
password="123456">
jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
javaTypeResolver>
<javaModelGenerator targetPackage="com.sqlb.pojo"
targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
<property name="constructorBased" value="true"/>
<property name="trimStrings" value="true"/>
<property name="immutable" value="false"/>
javaModelGenerator>
<sqlMapGenerator targetPackage="com.sqlb.mapper"
targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
sqlMapGenerator>
<javaClientGenerator targetPackage="com.sqlb.mapper"
targetProject="src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
javaClientGenerator>
<table tableName="reguser" domainObjectName="User"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
table>
<table schema="" tableName="tb_content">table>
<table schema="" tableName="tb_content_category">table>
<table schema="" tableName="tb_item">table>
<table schema="" tableName="tb_item_cat">table>
<table schema="" tableName="tb_item_desc">table>
<table schema="" tableName="tb_item_param">table>
<table schema="" tableName="tb_item_param_item">table>
<table schema="" tableName="tb_order">table>
<table schema="" tableName="tb_order_item">table>
<table schema="" tableName="tb_order_shipping">table>
<table schema="" tableName="tb_user">table>
context>
generatorConfiguration>
配置当中,classPathEntry
表示的是mysql-connector-java-5.1.32.jar
的绝对路径,不要搞错了。什么?你找不到该jar包的路径。好吧,File---->settings---->Maven
,如下图:
去这个路径找吧,根据依赖的坐标,就可以找到对应的jar包了。
运行有很多种方法,这里推荐一个最简单的:
因为之前添加了插件,就会产生mybatis-generator
,就是刚才添加的哪个插件,好了,双击运行,代码就出来了。
Oracle
与Mysql
同理。
<dependencies>
<dependency>
<groupId>com.oraclegroupId>
<artifactId>ojdbcartifactId>
<version>6version>
dependency>
<dependency>
<groupId>org.mybatis.generatorgroupId>
<artifactId>mybatis-generator-coreartifactId>
<version>1.3.6version>
dependency>
dependencies>
<repositories>
<repository>
<id>TalanRepositoryid>
<url>http://nexus.talanlabs.com/content/repositories/releases/url>
repository>
repositories>
<build>
<finalName>taotao-code-generatorfinalName>
<plugins>
<plugin>
<groupId>org.mybatis.generatorgroupId>
<artifactId>mybatis-generator-maven-pluginartifactId>
<version>1.3.2version>
<configuration>
<configurationFile>
G:\bankproject\mybatis-generator\src\main\resources\generator\generatorConfig.xml
configurationFile>
<verbose>trueverbose>
<overwrite>trueoverwrite>
configuration>
plugin>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
<generatorConfiguration>
<classPathEntry
location="C:\Programs\apache-maven-3.5.2\local\repo\com\oracle\ojdbc\6\ojdbc-6.jar"/>
<context id="default" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
commentGenerator>
<jdbcConnection
driverClass="oracle.jdbc.OracleDriver"
connectionURL="jdbc:oracle:thin:@192.168.10.56:1521:sxlib"
userId="tt_rdv2"
password="tt_rdv2oracle">
jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
javaTypeResolver>
<javaModelGenerator targetPackage="com.sx.mybatisgenerator.pojo"
targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
<property name="constructorBased" value="true"/>
<property name="trimStrings" value="true"/>
<property name="immutable" value="false"/>
javaModelGenerator>
<sqlMapGenerator targetPackage="com.sx.mybatisgenerator.mapper"
targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
sqlMapGenerator>
<javaClientGenerator targetPackage="com.sx.mybatisgenerator.mapper"
targetProject="src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
javaClientGenerator>
<table tableName="BK_PASSPORT_INFO" domainObjectName="PassportInfo"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
table>
context>
generatorConfiguration>