首页 > 编程语言 > IDEA集成MyBatis Generator插件的使用
2020
10-08

IDEA集成MyBatis Generator插件的使用

1、修改maven的pom文件

只需要将如下依赖添加到pom.xml文件中即可。(注意此处是以plugin的方式,放在<plugins> </plugins>中间即可)

<plugin>
  <groupId>org.mybatis.generator</groupId>
  <artifactId>mybatis-generator-maven-plugin</artifactId>
  <version>1.3.2</version>
</plugin>

2、编写generatorConfig.xml

需要特别注意的是:在IDEA开发环境下,这个文件需要放置在resources的根目录下面

文件内容如下

<?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="C:\Users\Administrator\.DataGrip2017.3\config\jdbc-drivers\MySQL Connector\J\5.1.45\mysql-connector-java-5.1.45-bin.jar"/>
  <context id="DB2Tables" targetRuntime="MyBatis3">
    <commentGenerator>
      <property name="suppressDate" value="true"/>
      <!-- 是否去除自动生成的注释 true:是 : false:否 -->
      <property name="suppressAllComments" value="true"/>
    </commentGenerator>
    <!--数据库链接URL,用户名、密码 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1/mysdql" userId="root" password="root">
    </jdbcConnection>
    <javaTypeResolver>
      <property name="forceBigDecimals" value="false"/>
    </javaTypeResolver>
    <!-- 生成模型的包名和位置-->
    <javaModelGenerator targetPackage="com.yingjun.ssm.entity" targetProject="src/main/java">
      <property name="enableSubPackages" value="true"/>
      <property name="trimStrings" value="true"/>
    </javaModelGenerator>
    <!-- 生成映射文件的包名和位置-->
    <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
      <property name="enableSubPackages" value="true"/>
    </sqlMapGenerator>
    <!-- 生成DAO的包名和位置-->
    <javaClientGenerator type="XMLMAPPER" targetPackage="com.yingjun.ssm.dao" targetProject="src/main/java">
      <property name="enableSubPackages" value="true"/>
    </javaClientGenerator>
    <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
    <table tableName="t_activity" domainObjectName="Activity" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  
  </context>
</generatorConfiguration>

文件的位置如下

3、创建maven运行项

到此这篇关于IDEA集成MyBatis Generator插件的使用的文章就介绍到这了,更多相关IDEA集成MyBatis Generator 内容请搜索自学编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持自学编程网!

编程技巧