maven+mybatis-generator插件反向生成源代码
通过maven+mybatis-generator插件反向生成源代码,如有一个table表为resource,那么将自动生成这样三个文件:Resource.java类、ResourceMapper.java类ResourceMapper.xml配置文件。
生成的文件如图:
maven标识符pom.xml文件配置如下:
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
mybatis-generator.xml文件配置如下(注意此文件放在src/main/resources目录下,同时配置项targetProject目录必须存在,targetPackage目录会自动生成):
<?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="H:\soft\jdbcdriver\mysql\mysql-connector-java-5.1.6-bin.jar" />
<context id="context" targetRuntime="MyBatis3">
<!-- 消除插件自动生成的垃圾注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8"
userId="root" password="yyh081616" />
<!-- pojo,mapper等源文件的路径 -->
<javaModelGenerator targetPackage="cn.yyh.pojo"
targetProject="E:\autocode" />
<sqlMapGenerator targetPackage="cn.yyh.mapper"
targetProject="E:\autocode" />
<javaClientGenerator targetPackage="cn.yyh.mapper"
targetProject="E:\autocode" type="XMLMAPPER" />
<!-- 表信息 -->
<table schema="test" tableName="resource" enableCountByExample="false"
enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" />
<!-- <table schema="test" tableName="user" /> -->
</context>
</generatorConfiguration>
整个生成源代码的项目结构如下(注意generatorConfig.xml的路径):
最后执行:clean mybatis-generator:generate命令即可生成源文件。
maven+mybatis-generator插件反向生成源代码的更多相关文章
- Eclipse 使用mybatis generator插件自动生成代码
Eclipse 使用mybatis generator插件自动生成代码 标签: mybatis 2016-12-07 15:10 5247人阅读 评论(0) 收藏 举报 .embody{ paddin ...
- Mybatis generator 数据库反向生成插件的使用
直接上干货: 可生成数据库表对应的po mpper接口文件 mapper.xml文件.文件中自动配置了部分常用的dao层方法.用于快速快发. 1.pom中引入插件: <plugin> & ...
- 使用Mybatis Generator插件自动生成映射文件(cmd无法进入文件,dns服务器对区域没有权威等问题)遇到问题
使用Mybatis Genertor插件自动生MyBatis所需要的DAO接口,实体模型类,Mapping映射文件,将生成的代码赋值到项目工程中即可. 有命令行,Eclipse插 ...
- MyEclipse下安装MyBatis Generator代码反向生成工具
一.离线方式: 在http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite/下载 featur ...
- IDEA Maven Mybatis generator 自动生成代码
IDEA Maven Mybatis generator 自动生成代码 一.安装配置maven以及在Idea中配置maven 安装过程步骤可以看上面的博文,里面介绍得很详细. 二.建数据表 DROP ...
- IDEA Maven Mybatis generator 自动生成代码(实例讲解)(转)
IDEA Maven Mybatis generator 自动生成代码(实例讲解) MyBatis Generator • 简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器,可以快速的 ...
- Mybatis分页-利用Mybatis Generator插件生成基于数据库方言的分页语句,统计记录总数 (转)
众所周知,Mybatis本身没有提供基于数据库方言的分页功能,而是基于JDBC的游标分页,很容易出现性能问题.网上有很多分页的解决方案,不外乎是基于Mybatis本机的插件机制,通过拦截Sql做分页. ...
- Mybatis Generator的model生成中文注释,支持oracle和mysql(通过实现CommentGenerator接口的方法来实现)
自己手动实现的前提,对maven项目有基本的了解,在本地成功搭建了maven环境,可以参考我之前的文章:maven环境搭建 项目里新建表时model,mapper以及mapper.xml基本都是用My ...
- Mybatis-Generator_学习_02_使用Mapper专用的MyBatis Generator插件
源码见:https://github.com/shirayner/tk-mybatis-generator 一.要点 二.具体实现 1.项目结构 2.配置 pm.xml <?xml versio ...
随机推荐
- maven的一些常用配置
配置JDK<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupI ...
- linq检索带命名空间的xml
XElement el = XElement.Load(fil); XNamespace ns = "http://schemas.microsoft.com/ado/2009/11/edm ...
- 160多个android开源代码汇总
第一部分 个性化控件(View) 主要介绍那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.Pro ...
- MINUS,INTERSECT,UNION浅析
转载:http://blog.csdn.net/gan690416372/article/details/5012397 SQL语句中的三个关键字:MINUS(减去),INTERSECT(交集)和UN ...
- JavaScript动画附源码(一)
JavaScript完成动画程序 1,效果图: 以上是纯CSS+JavaScript实现的.点击关闭按钮可以动态关闭这个方框.兼容IE/FF/Chrome.这样的效果如果用jquery实现起来 ...
- css笔记——css 实现自定义按钮
css实现自定义按钮的样式实际上很早就有了,只是会用的人不是很多,里面涉及到了最基础的css写法,在火狐中按钮还是会显示出来,这时需要将i标签的背景设置为白色,同时z-index设置比input高一些 ...
- javascript笔记---貌似大叔
1.原型式继承和类式继承的区别 在基于类的面向对象方式中,对象(object)依靠类(class)来产生.而在基于原型的面向对象方式中,对象(object)则是依靠 构造器(constructor)利 ...
- 【转】简单理解socket
题外话 前几天和朋友聊天,朋友问我怎么最近不写博客了,一个是因为最近在忙着公司使用的一些控件的开发,浏览器兼容性搞死人:但主要是因为这段时间一直在看html5的东西,看到web socket时觉得很有 ...
- CSU-ACM2016暑假集训训练1-二分搜索 A - Can you find it?
Time Limit:3000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Description Give yo ...
- Windows下Android模拟环境的搭建