Eclipse 使用mybatis generator插件自动生成代码
<h1>
<span class="link_title"><a href="/dings503/article/details/53506030">
Eclipse 使用mybatis generator插件自动生成代码
</a>
</span>
</h1>
<div class="article_manage clearfix">
<div class="article_l">
<span class="link_categories">
标签:
<a href="http://www.csdn.net/tag/mybatis" target="_blank" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_tag']);">mybatis</a>
</span>
</div>
<div class="article_r">
<span class="link_postdate">2016-12-07 15:10</span>
<span class="link_view" title="阅读次数">5247人阅读</span>
<span class="link_comments" title="评论次数"> <a href="#comments" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_pinglun'])">评论</a>(0)</span>
<span class="link_collect tracking-ad" data-mod="popu_171"> <a href="javascript:void(0);" onclick="javascript:collectArticle('Eclipse+%e4%bd%bf%e7%94%a8mybatis+generator%e6%8f%92%e4%bb%b6%e8%87%aa%e5%8a%a8%e7%94%9f%e6%88%90%e4%bb%a3%e7%a0%81','53506030');return false;" title="收藏" target="_blank">收藏</a></span>
<span class="link_report"> <a href="#report" onclick="javascript:report(53506030,2);return false;" title="举报">举报</a></span>
</div>
</div> <style type="text/css">
.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;
}
</style>
<script type="text/javascript">
$(function () {
try
{
var lib = eval("("+$("#lib").attr("value")+")");
var html = "";
if (lib.err == 0) {
$.each(lib.data, function (i) {
var obj = lib.data[i];
//html += '<img src="' + obj.logo + '"/>' + obj.name + " ";
html += ' <a href="' + obj.url + '" target="_blank">';
html += ' <img src="' + obj.logo + '">';
html += ' <em><b>' + obj.name + '</b></em>';
html += ' </a>';
});
if (html != "") {
setTimeout(function () {
$("#lib").html(html);
$("#embody").show();
}, 100);
}
}
} catch (err)
{ }
});
</script>
<div class="category clearfix">
<div class="category_l">
<img src="http://static.blog.csdn.net/images/category_icon.jpg">
<span>分类:</span>
</div>
<div class="category_r">
<label>
<span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_fenlei']);">mybatis<em></em></span>
</label>
</div>
</div>
<div class="bog_copyright">
<p class="copyright_p">版权声明:本文为博主原创文章,未经博主允许不得转载。</p>
</div>
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
PS:
targetProject的配置如果写绝对路径可能出错: Project D: does not exist
最好使用绝对路径。
3. 生成代码文件
选中generatorConfig.xml文件,右键选择Generate MyBatis/IBATIS Artifacts即可
<div id="digg" articleid="53506030">
<dl id="btnDigg" class="digg digg_disable" onclick="btndigga();">
<dt>顶</dt>
<dd>54</dd>
</dl>
<dl id="btnBury" class="digg digg_disable" onclick="btnburya();">
<dt>踩</dt>
<dd>1</dd>
</dl>
</div>
<div class="tracking-ad" data-mod="popu_222"><a href="javascript:void(0);" target="_blank"> </a> </div>
<div class="tracking-ad" data-mod="popu_223"> <a href="javascript:void(0);" target="_blank"> </a></div>
<script type="text/javascript">
function btndigga() {
$(".tracking-ad[data-mod='popu_222'] a").click();
}
function btnburya() {
$(".tracking-ad[data-mod='popu_223'] a").click();
}
</script>
<div style="clear:both; height:10px;"></div>
<div class="similar_article">
<h4></h4>
<div class="similar_c" style="margin:20px 0px 0px 0px">
<div class="similar_c_t">
相关文章推荐
</div>
<div class="similar_wrap tracking-ad" data-mod="popu_36" style="max-height: 250px; background-color: rgb(204, 232, 207);">
<ul class="similar_list fl">
<li>
<em>•</em>
<a href="http://blog.csdn.net/pucao_cug/article/details/64499355" title="Maven插件之mybatis-generator(mybatis自动生成实体代码的插件)" strategy="BlogCommendFromBaidu_0" target="_blank">Maven插件之mybatis-generator(mybatis自动生成实体代码的插件)</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/huiyiCourse/series_detail/60?utm_source=wx2" title="轻松拿下Linux进程、线程和调度" strategy="undefined" target="_blank">轻松拿下Linux进程、线程和调度</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/haoui123/article/details/70209038" title="Eclipse插件:mybatis generator的使用步骤" strategy="BlogCommendFromBaidu_1" target="_blank">Eclipse插件:mybatis generator的使用步骤</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/huiyiCourse/series_detail/61?utm_source=blog7" title="30天掌握机器学习升级版" strategy="undefined" target="_blank">30天掌握机器学习升级版</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/Marksinoberg/article/details/51241383" title="MyBatis Generator For Eclipse 插件安装" strategy="BlogCommendFromBaidu_2" target="_blank">MyBatis Generator For Eclipse 插件安装</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/course/detail/3049?utm_source=blog7" title="Python网络爬虫快速入门实战" strategy="undefined" target="_blank">Python网络爬虫快速入门实战</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/Wild_Elegance_k/article/details/47609649" title="MyBatis-Generator在Eclipse上配置及使用" strategy="BlogCommendFromBaidu_3" target="_blank">MyBatis-Generator在Eclipse上配置及使用</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/course/detail/474?utm_source=blog7" title="最适合自学的C++基础知识" strategy="undefined" target="_blank">最适合自学的C++基础知识</a>
</li>
</ul>
<ul class="similar_list fr">
<li>
<em>•</em>
<a href="http://download.csdn.net/download/gxl442172663/7624747" title="mybatis-generator eclipse插件离线安装包" strategy="BlogCommendFromBaidu_4" target="_blank">mybatis-generator eclipse插件离线安装包</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/course/detail/3719?utm_source=blog7" title="一招学会Android自定义控件" strategy="undefined" target="_blank">一招学会Android自定义控件</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/baalhuo/article/details/51469675" title="MyEclipse使用MyBatis Generator 工具逆向生成映射文件" strategy="BlogCommendFromBaidu_5" target="_blank">MyEclipse使用MyBatis Generator 工具逆向生成映射文件</a>
</li>
<li>
<em>•</em>
<a href="http://edu.csdn.net/course/detail/1128?utm_source=blog7" title="从零练就iOS高手" strategy="undefined" target="_blank">从零练就iOS高手</a>
</li>
<li>
<em>•</em>
<a href="http://download.csdn.net/download/a318199328/9604889" title="Eclipse MyBatis Generator插件和使用说明" strategy="BlogCommendFromBaidu_6" target="_blank">Eclipse MyBatis Generator插件和使用说明</a>
</li>
<li>
<em>•</em>
<a href="http://download.csdn.net/download/fullbug/9659695" title="mybatis-eclipse插件及生成代码说明" strategy="BlogCommendFromBaidu_7" target="_blank">mybatis-eclipse插件及生成代码说明</a>
</li>
<li>
<em>•</em>
<a href="http://blog.csdn.net/u011679955/article/details/52679732" title="使用Eclipse的Generator MyBatis/iBatis Artifacts插件自动生成代码,与spring集成" strategy="BlogCommendFromCsdn_8" target="_blank">使用Eclipse的Generator MyBatis/iBatis Artifacts插件自动生成代码,与spring集成</a>
</li>
<li>
<em>•</em>
<a href="http://download.csdn.net/download/tolcf/9456659" title="mybatis-generator 代码自动生成工具" strategy="BlogCommendFromCsdn_9" target="_blank">mybatis-generator 代码自动生成工具</a>
</li>
</ul>
</div>
</div>
</div>