• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

IDEA MyBatis Plugins自动生成实体类和mapper.xml

mybatis 搞代码 4年前 (2022-01-09) 31次浏览 已收录 0个评论

前言

如何下载和使用MyBatis Generator 插件,只说代码,不讲感情。如果有问题还请多多指点。

开发环境

  • 开发工具:IntelliJ IDEA 2018.1.1 x64
  • dk版本:1.8.0_171
  • 工程构建工具:maven 版本3.2.5
  • 数据库 mysql

IDEA 下载MyBatis Generator 插件

1.首先在File——Settings——点击Plugins,搜索框中搜索mybatis,选择mybatis-plugins,点击安装(由于我的已经安装过,所以没有绿色的Install按钮,而变成了instleaed,)安装完成后点击图片上那个位置的按钮(我忘了他叫什么了)之后会让你重启IDEA :

修改maven的pom文件

(注意此处是以plugin的方式,要放在plugins /plugins 里面)

<plugins>
      <!-- mybatis generator 自动生成代码插件 -->
      <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.5</version>
        <configuration>
          <!--配置文件的位置-->
          <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
          <a style="color:transparent">本文来源gao($daima.com搞@代@#码(网5</a><overwrite>true</overwrite>
          <verbose>true</verbose>
        </configuration>
      </plugin>
 </plugins>

新建一个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="G:\lianjieshujukuqudonglib\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/xx" userId="root" password="root">
    </jdbcConnection>
    <javaTypeResolver>
      <property name="forceBigDecimals" value="false"/>
    </javaTypeResolver>
    <!-- 生成模型的包名和位置-->
    <javaModelGenerator targetPackage="com.cn.wjp.springboot.entity" targetProject="src/main/java">
      <property name="enableSubPackages" value="true"/>
      <property name="trimStrings" value="true"/>
    </javaModelGenerator>
    <!-- 生成映射文件的包名和位置-->
    <sqlMapGenerator targetPackage="main.resources.mapping" targetProject="src">
      <!-- enableSubPackages:是否让schema作为包的后缀 -->
      <property name="enableSubPackages" value="false" />
    </sqlMapGenerator>
    <!-- 生成DAO的包名和位置-->
    <javaClientGenerator type="XMLMAPPER" targetPackage="com.cn.wjp.springboot.dao" targetProject="src/main/java">
      <property name="enableSubPackages" value="true"/>
    </javaClientGenerator>
    <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
    <table tableName="sc"
        domainObjectName="sc"
        enableCountByExample="false"
        enableUpdateByExample="false"
        enableDeleteByExample="false"
        enableSelectByExample="false"
        selectByExampleQueryId="false">

    </table>

  </context>
</generatorConfiguration>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:IDEA MyBatis Plugins自动生成实体类和mapper.xml
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址