generator 主要是自動生成 DAO绣版、Entity、Mapper.xml
配置 generator
所依賴的工具
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
<!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-maven-plugin -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven/maven-plugin-api -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.0.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven/maven-project -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
//引用mybatis-generator-maven-plugin
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
generatorConfig
配置
<?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:數(shù)據(jù)庫的JDBC驅(qū)動 -->
<classPathEntry
location="C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.31\mysql-connector-java-5.1.31.jar" />
<context id="MysqlTables" targetRuntime="MyBatis3">
<!-- 注意這里面的順序確定的歼疮,不能隨變更改 -->
<!-- 自定義的分頁插件 <plugin type="com.deppon.foss.module.helloworld.shared.PaginationPlugin"/> -->
<!-- 可選的(0 or 1) -->
<!-- 注釋生成器 -->
<commentGenerator>
<!-- 是否去除自動生成的注釋 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 必須的(1 required) -->
<!--數(shù)據(jù)庫連接的信息:驅(qū)動類杂抽、連接地址、用戶名韩脏、密碼 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/work_attendence"
userId="root" password="">
</jdbcConnection>
<!-- 可選的(0 or 1) -->
<!-- 類型轉(zhuǎn)換器或者加類型解析器 -->
<!-- 默認(rèn)false缩麸,把JDBC DECIMAL 和 NUMERIC 類型解析為 Integer true,把JDBC DECIMAL 和
NUMERIC 類型解析為java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 必須的(1 required) -->
<!-- java模型生成器 -->
<!-- targetProject:自動生成代碼的位置 -->
<javaModelGenerator targetPackage="com.mylzs.cn.user.entity"
targetProject="E:\JAVA-WEB\WorkAdministration\src\main\java"
>
<!-- TODO enableSubPackages:是否讓schema作為包的后綴 -->
<property name="enableSubPackages" value="true" />
<!-- 從數(shù)據(jù)庫返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 必須的(1 required) -->
<!-- map xml 生成器 -->
<sqlMapGenerator targetPackage="com.mylzs.cn.user.dao"
targetProject="E:\JAVA-WEB\WorkAdministration\src\main\java">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 可選的(0 or 1) -->
<!-- mapper 或者就是dao接口生成器 -->
<javaClientGenerator targetPackage="com.mylzs.cn.user.dao"
targetProject="E:\JAVA-WEB\WorkAdministration\src\main\java"
type="XMLMAPPER">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 必須的(1...N) -->
<!-- pojo 實體生成器 -->
<!-- tableName:用于自動生成代碼的數(shù)據(jù)庫表赡矢;domainObjectName:對應(yīng)于數(shù)據(jù)庫表的javaBean類名 -->
<!-- schema即為數(shù)據(jù)庫名 可不寫 -->
<table tableName="user" domainObjectName="User"
enableInsert="true" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false">
<!-- 忽略字段 可選的(0 or 1) -->
<!-- <ignoreColumn column="is_use" /> -->
<!--//無論字段是什么類型杭朱,生成的類屬性都是varchar阅仔。 可選的(0 or 1) 測試無效 -->
<!-- <columnOverride column="city_code" jdbcType="VARCHAR" /> -->
</table>
</context>
</generatorConfiguration>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者