Mybatis generator 配置入门
Mybatis generator 插件的使用可以大大提高我们开发的效率,可根据数据库快速生成 实体类,mapper文件以及对应的
xml映射文件。
配置方法:
第一步:
在SpringBoot的pom文件的插件配置中添加如下配置:
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<!--generator生成配置覆盖重写文件-->
<configuration>
<overwrite>true</overwrite>
</configuration>
</plugin>
第二步:
下载jar包:
mysql-connector-java-5.1.6.jar
第三步:
参考Mybatis Generator 配置详解文章
https://www.imooc.com/article/21444
在resources目录下新建generator配置文件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>
<!-- 运行系统下的的绝对路径-->
<classPathEntry location="D:\WorkSpace\IdeaSpace\mysql-connector-java-5.1.6.jar" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<!-- 不再追加xml内容-->
<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />
<!-- 配置不生成备注-->
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/mimall?characterEncoding=utf-8"
userId="root"
password="root">
</jdbcConnection>
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<javaModelGenerator targetPackage="cn.blogsx.mimall.pojo" 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="cn.blogsx.mimall.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<table tableName="mall_order" domainObjectName="Order" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>
<!-- <table tableName="mall_order" domainObjectName="Order" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>-->
<table tableName="mall_order_item" domainObjectName="OrderItem" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>
</context>
</generatorConfiguration>
配置完成后即可在终端输入如下命令生成相应的文件:
mvn mybatis-generator:generate

浙公网安备 33010602011771号