成果
成果步骤:
1.生成数据库表
库结构2.maven项目中配置:
a.src/resources目录下新增generatorConfig.xml文件,内容如下:
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- mysql-connector-java 版本需要与pom中引得版本一致 -->
<classPathEntry location="/Users/hedonghui/Documents/17usoft/repository/mysql/mysql-connector-java/8.0.28/mysql-connector-java-8.0.28.jar" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<!-- 不加注释,因为默认注释是英文的 -->
<commentGenerator>
<property name="addRemarkComments" value="true"/>
<property name="suppressDate" value="true"/>
</commentGenerator>
<!-- 数据库连接信息 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://ip:端口/tablename?characterEncoding=utf-8&useSSL=false&serverTimezone=UTC"
userId="username"
password="password">
</jdbcConnection>
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- targetPackage 文件生成在指定包下,targetProject 路径-->
<javaModelGenerator targetPackage="com.ly.flight.mock.entity" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="mappers" targetProject="src/main/resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.ly.flight.mock.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- domainObjectName 即生成后entity的名字 -->
<table tableName = "tablename1" domainObjectName="tablename1" />
<table tableName = "tablename2" domainObjectName="tablename2" />
<table tableName = "tablename3" domainObjectName="tablename3" />
<table tableName = "tablename4" domainObjectName="tablename4" />
<table tableName = "tablename5" domainObjectName="tablename5" />
<table tableName = "tablename6" domainObjectName="tablename6" />
</context>
</generatorConfiguration>
b.创建对应的targetPackage包
代码结构3.在pom.xml中引入jar包
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.6</version>
</dependency>
<dependency>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
</dependencies>
<configuration>
<overwrite>true</overwrite>
<configurationFile>真实路径/generatorConfig.xml</configurationFile>
</configuration>
</plugin>
网友评论