一、依赖jar包
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.29</version>
</dependency>
二、核心配置文件:generatorConfig.xml
<?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>
<context id="GCCSMysql" targetRuntime="MyBatis3" defaultModelType="flat">
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<property name="mergeable" value="false"></property>
<plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"/>
<commentGenerator>
<!-- 抑制警告 -->
<property name="suppressTypeWarnings" value="true"/>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="false"/>
<property name="javaFileEncoding" value="UTF-8"/>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/db_test_user?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true"
userId="root"
password="root">
</jdbcConnection>
<javaModelGenerator targetPackage="com.mybatis.test.model.user"
targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.mybatis.test.mapper.user"
targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<javaClientGenerator targetPackage="com.mybatis.test.mapper.user"
targetProject="src/main/java"
type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<table tableName="t_custom" domainObjectName="Custom"
enableInsert="true"
enableSelectByPrimaryKey="true"
enableSelectByExample="true"
enableUpdateByPrimaryKey="true"
enableDeleteByPrimaryKey="true"
enableDeleteByExample="true"
enableCountByExample="true"
enableUpdateByExample="true"
selectByPrimaryKeyQueryId="true"
selectByExampleQueryId="true">
</table>
<table tableName="t_seller" domainObjectName="Seller"
enableInsert="true"
enableSelectByPrimaryKey="true"
enableSelectByExample="true"
enableUpdateByPrimaryKey="true"
enableDeleteByPrimaryKey="true"
enableDeleteByExample="true"
enableCountByExample="true"
enableUpdateByExample="true"
selectByPrimaryKeyQueryId="true"
selectByExampleQueryId="true">
</table>
</context>
</generatorConfiguration>
三、maven pom添加编译配置
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<configuration>
<verbose>false</verbose>
<overwrite>false</overwrite>
</configuration>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
四、运行
![]()
MybatisGenerator 数据库逆向生成代码工具二、核心配置文件:generatorConfig.xml三、maven pom添加编译配置四、运行
![]()
MybatisGenerator 数据库逆向生成代码工具二、核心配置文件:generatorConfig.xml三、maven pom添加编译配置四、运行 之后弹出运行配置框,为当前配置配置一个名称,这里其名为"generator",然后在 “Command line” 选项中输入“mybatis-generator:generate -e”
这里加了“-e ”选项是为了让该插件输出详细信息,这样可以帮助我们定位问题。
![]()
MybatisGenerator 数据库逆向生成代码工具二、核心配置文件:generatorConfig.xml三、maven pom添加编译配置四、运行 如果添加成功,则会在run 选项中有“generator” 选项,如下:![]()
MybatisGenerator 数据库逆向生成代码工具二、核心配置文件:generatorConfig.xml三、maven pom添加编译配置四、运行 点击运行![]()
MybatisGenerator 数据库逆向生成代码工具二、核心配置文件:generatorConfig.xml三、maven pom添加编译配置四、运行
相关推荐:
快速搭建springboot项目
springboot集成mybatis
springboot集成hibernate