中文手册 请参考
英文手册 请参考
方式一:maven
(1)、配置pop.xml的插件
增加 org.mybatis.generator插件
-
<project xmlns="" xmlns:xsi=""
-
xsi:schemaLocation=" ">
-
<modelVersion>4.0.0</modelVersion>
-
<groupId>com.elements</groupId>
-
<artifactId>mybatisbase</artifactId>
-
<version>0.0.1-SNAPSHOT</version>
-
-
<build>
-
<plugins>
-
-
<plugin>
-
<groupId>org.mybatis.generator</groupId>
-
<artifactId>mybatis-generator-maven-plugin</artifactId>
-
<version>1.3.2</version>
-
</plugin>
-
</plugins>
-
-
</build>
-
-
-
<dependencies>
-
<dependency>
-
<groupId>org.mybatis</groupId>
-
<artifactId>mybatis</artifactId>
-
<version>3.2.6</version>
-
-
</dependency>
-
-
<dependency>
-
<groupId>junit</groupId>
-
<artifactId>junit</artifactId>
-
<version>4.12</version>
-
<scope>test</scope>
-
</dependency>
-
-
<dependency>
-
<groupId>c3p0</groupId>
-
<artifactId>c3p0</artifactId>
-
<version>0.9.1.2</version>
-
</dependency>
-
-
<dependency>
-
<groupId>mysql</groupId>
-
<artifactId>mysql-connector-java</artifactId>
-
<version>6.0.2</version>
-
</dependency>
-
</dependencies>
-
</project>
(2)、编写 generatorConfig.xml
路径:${basedir}/src/main/resources/generatorConfig.xml
-
<?xml version="1.0" encoding="UTF-8"?>
-
<!DOCTYPE generatorConfiguration
-
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
-
"">
-
-
<generatorConfiguration>
-
-
<classPathEntry location="E:\webnet\maven\mysql\mysql-connector-java\5.1.30\mysql-connector-java-5.1.30.jar" />
-
-
<context id="mysqlTables" targetRuntime="MyBatis3">
-
-
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
-
connectionURL="jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf8&useSSL=true&serverTimezone=UTC"
-
userId="mybatis"
-
password="mybatis">
-
</jdbcConnection>
-
-
<javaTypeResolver >
-
<property name="forceBigDecimals" value="false" />
-
</javaTypeResolver>
-
-
<javaModelGenerator targetPackage="com.elements.usernation.model" targetProject="src/main/java">
-
<property name="enableSubPackages" value="true" />
-
<property name="trimStrings" value="true" />
-
</javaModelGenerator>
-
-
<sqlMapGenerator targetPackage="com.elements.usernation.dao" targetProject="src/main/java">
-
<property name="enableSubPackages" value="true" />
-
</sqlMapGenerator>
-
-
<javaClientGenerator type="XMLMAPPER" targetPackage="com.elements.usernation.dao" targetProject="src/main/java">
-
<property name="enableSubPackages" value="true" />
-
</javaClientGenerator>
-
-
<!-- 配置表信息 -->
-
<table schema="mybatis" tableName="usernation" enableCountByExample="false"
-
enableDeleteByExample="false" enableSelectByExample="false"
-
enableUpdateByExample="false">
-
<!-- schema即为数据库名 tableName为对应的数据库表 domainObjectName是要生成的实体类 enable*ByExample
-
是否生成 example类 -->
-
-
<!-- 忽略列,不生成bean 字段 <ignoreColumn column="FRED" /> -->
-
<!-- 指定列的java数据类型 <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR"
-
/> -->
-
</table>
-
-
</context>
-
</generatorConfiguration>
(3)、生成代码
项目 右键--》run as --》 maven bulid --》弹出对话框 --》在goals中输入mybatis-generator:generate
方式二:eclipse插件的安装
阅读(5157) | 评论(0) | 转发(0) |