您的位置:首页 > 编程语言 > Java开发

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

2017-09-06 13:38 519 查看

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

标签: mybatis 2016-12-07 15:10 5247人阅读 评论(0) 收藏 举报 .embody { padding: 10px 10px 10px; margin: 0 -20px; border-bottom: solid 1px #ededed }
.embody_b { margin: 0; padding: 10px 0 }
.embody .embody_t,.embody .embody_c { display: inline-block; margin-right: 10px }
.embody_t { font-size: 12px; color: #999 }
.embody_c { font-size: 12px }
.embody_c img,.embody_c em { display: inline-block; vertical-align: middle }
.embody_c img { width: 30px; height: 30px }
.embody_c em { margin: 0 20px 0 10px; color: #333; font-style: normal }

分类: mybatis 版权声明:本文为博主原创文章,未经博主允许不得转载。

目录(?)[+]

下载mybatis generator插件
使用插件
生成代码文件

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


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

3. 生成代码文件

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

顶 54 踩 1 上一篇Spring学习笔记(二)
下一篇eclipse项目中引入jquery.min.js报错

相关文章推荐 • Maven插件之mybatis-generator(mybatis自动生成实体代码的插件)
轻松拿下Linux进程、线程和调度
Eclipse插件:mybatis generator的使用步骤
30天掌握机器学习升级版
MyBatis Generator For Eclipse 插件安装
Python网络爬虫快速入门实战
MyBatis-Generator在Eclipse上配置及使用
最适合自学的C++基础知识
mybatis-generator eclipse插件离线安装包
一招学会Android自定义控件
MyEclipse使用MyBatis Generator 工具逆向生成映射文件
从零练就iOS高手
Eclipse MyBatis Generator插件和使用说明
mybatis-eclipse插件及生成代码说明
使用Eclipse的Generator MyBatis/iBatis Artifacts插件自动生成代码,与spring集成
mybatis-generator 代码自动生成工具
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: