Eclipse 使用mybatis generator插件自动生成代码

Eclipse 使用mybatis generator插件自动生成代码

标签: mybatis
5247人阅读 评论(0) 收藏 举报
category_icon.jpg 分类:
mybatis

1. 下载mybatis generator插件

下载地址:https://github.com/mybatis/generator/releases

下载完成后,解压,将features和plugins文件夹的内容复制到eclipse的相应文件夹中,重启eclipse即可。

2. 使用插件

选中添加generatorConfig文件的项目,右键new–>other

这里写图片描述

生成的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:数据库的JDBC驱动的jar包地址 -->
    <classPathEntry
        location="D:\software\eclipse\workspace\UserRegister\WebContent\WEB-INF\lib\mysql-connector-java-5.1.22-bin.jar" />
    <context id="DB2Tables" targetRuntime="MyBatis3">
        <commentGenerator>
            <!-- 抑制警告 -->
            <property name="suppressTypeWarnings" value="true" />
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="true" />
            <!-- 是否生成注释代时间戳 -->
            <property name="suppressDate" value="true" />
        </commentGenerator>

        <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://localhost/test" userId="root"
            password="root">
        </jdbcConnection>

        <javaModelGenerator targetPackage="com.demo.domain"
            targetProject="UserRegister\src">
            <property name="enableSubPackages" value="false" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="com.demo.mapper"
            targetProject="UserRegister\src">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>

        <javaClientGenerator type="XMLMAPPER"
            targetPackage="com.demo.dao" targetProject="UserRegister\src">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>

        <!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->
        <!-- <table schema="untodo" tableName="T_USER" domainObjectName="User"/> -->
        <!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
        <!-- <table schema="untodo" tableName="T_USER" domainObjectName="User" 
            enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" 
            enableSelectByExample="false" selectByExampleQueryId="false"/> -->
        <!--生成对应表及类名 -->
        <table schema="general" tableName="T_USERINFO" domainObjectName="User">
            <!--domain字段的命名规则,false:默认为驼峰命名 true:按数据库真实命名 -->
            <property name="useActualColumnNames" value="false" />
            <!-- 忽略列,不生成bean 字段 -->
            <!-- <ignoreColumn column="FRED" /> -->
            <!-- 指定列的java数据类型 -->
            <!-- <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> -->
        </table>
    </context>

</generatorConfiguration>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
save_snippets.png

PS:
targetProject的配置如果写绝对路径可能出错: Project D: does not exist
最好使用绝对路径。

3. 生成代码文件

选中generatorConfig.xml文件,右键选择Generate MyBatis/IBATIS Artifacts即可

54
1
 
 

转载于:https://www.cnblogs.com/jpfss/p/7484370.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值