mybatis-generator1.3.6的使用
下载地址:
http://blog.mybatis.org/2017/12/mybatis-generator-version-136-released.html
参考了
http://blog.csdn.net/qr719169236/article/details/51086997
在使用mybatis开发的过程中,通常我们会给数据库的每张表编写对应的domain、dao、mapping,很简单,但是工作很大,所以我们通常会使用代码生成器帮我们自动生成。具体方法如下:
mybatis-generator 下载
generatorConfiguration文件配置
点击From the Command Line,显示must create an XML configuration file to run MBG from the command line,就是说必须要创建一个configuration 配置文件,然后执行下面的命令:
java -jar mybatis-generator-core-x.x.x.jar -configfile generatorConfig.xml
java -jar mybatis-generator-core-x.x.x.jar -configfile generatorConfig.xml -overwrite
java -cp mybatis-generator-core-x.x.x.jar org.mybatis.generator.api.ShellRunner -configfile generatorConfig.xml
java -cp mybatis-generator-core-x.x.x.jar org.mybatis.generator.api.ShellRunner -configfile generatorConfig.xml -overwrite
在lib目录下新建一个generatorConfig.xml文件,点击XML Configuration Reference 将里面的代码拷贝到 generatorConfig.xml 中
修改generatorConfig.xml文件。在上图中的代码中,classPathEntry为数据库连接驱动,多以将对应的jar文件放入lib文件中,location指定其路径。实例如下:
- <?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>
- <!--MySQL连接驱动-->
- <classPathEntry location="mysql-connector-java-5.1.9.jar" />
- <!--数据库链接URL,用户名、密码 -->
- <context id="MySQL" targetRuntime="MyBatis3">
- <commentGenerator>
- <property name="suppressDate" value="true"/>
- <!-- 是否去除自动生成的注释 true:是 : false:否 -->
- <property name="suppressAllComments" value="true"/>
- </commentGenerator>
- <jdbcConnection driverClass="com.mysql.jdbc.Driver"
- connectionURL="jdbc:mysql://127.0.0.1/test"
- userId="root"
- password="123456">
- </jdbcConnection>
- <!--是否启用java.math.BigDecimal-->
- <javaTypeResolver >
- <property name="forceBigDecimals" value="false" />
- </javaTypeResolver>
- <javaModelGenerator targetPackage="test.model" targetProject="src">
- <property name="enableSubPackages" value="true" />
- <property name="trimStrings" value="true" />
- </javaModelGenerator>
- <sqlMapGenerator targetPackage="test.xml" targetProject="src">
- <property name="enableSubPackages" value="true" />
- </sqlMapGenerator>
- <javaClientGenerator type="XMLMAPPER" targetPackage="test.dao" targetProject="src">
- <property name="enableSubPackages" value="true" />
- </javaClientGenerator>
- <table tableName="salary" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
- </table>
- <table tableName="persons" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
- </table>
- <table tableName="orders" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
- </table>
- </context>
- </generatorConfiguration>
- <?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>
- <!--MySQL连接驱动-->
- <classPathEntry location="mysql-connector-java-5.1.9.jar" />
- <!--数据库链接URL,用户名、密码 -->
- <context id="MySQL" targetRuntime="MyBatis3">
- <commentGenerator>
- <property name="suppressDate" value="true"/>
- <!-- 是否去除自动生成的注释 true:是 : false:否 -->
- <property name="suppressAllComments" value="true"/>
- </commentGenerator>
- <jdbcConnection driverClass="com.mysql.jdbc.Driver"
- connectionURL="jdbc:mysql://127.0.0.1/test"
- userId="root"
- password="123456">
- </jdbcConnection>
- <!--是否启用java.math.BigDecimal-->
- <javaTypeResolver >
- <property name="forceBigDecimals" value="false" />
- </javaTypeResolver>
- <javaModelGenerator targetPackage="test.model" targetProject="src">
- <property name="enableSubPackages" value="true" />
- <property name="trimStrings" value="true" />
- </javaModelGenerator>
- <sqlMapGenerator targetPackage="test.xml" targetProject="src">
- <property name="enableSubPackages" value="true" />
- </sqlMapGenerator>
- <javaClientGenerator type="XMLMAPPER" targetPackage="test.dao" targetProject="src">
- <property name="enableSubPackages" value="true" />
- </javaClientGenerator>
- <table tableName="salary" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
- </table>
- <table tableName="persons" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
- </table>
- <table tableName="orders" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
- </table>
- </context>
- </generatorConfiguration>
<?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> <!--MySQL连接驱动-->
<classPathEntry location="mysql-connector-java-5.1.9.jar" /> <!--数据库链接URL,用户名、密码 -->
<context id="MySQL" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1/test"
userId="root"
password="123456">
</jdbcConnection><!--是否启用java.math.BigDecimal-->
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver> <javaModelGenerator targetPackage="test.model" targetProject="src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator> <sqlMapGenerator targetPackage="test.xml" targetProject="src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator> <javaClientGenerator type="XMLMAPPER" targetPackage="test.dao" targetProject="src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator> <table tableName="salary" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
</table>
<table tableName="persons" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
</table>
<table tableName="orders" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>
Running MyBatis Generator
mybatis-generator1.3.6的使用的更多相关文章
- eclipse 4.5 离线安装mybatis generator1.3.6卡在Install New Software的解决方法
转载:https://blog.csdn.net/ssshen14/article/details/80004459 离线插件 下载:https://github.com/mybatis/genera ...
- mybatis generator插件开发
mybatis现在普遍使用的每一个人DAO框架.mybatis generator它可以基于数据库中的表结构,生成自己主动mybatis代码和配置文件,方便使用,当然,实际的使用过程中.generat ...
- MyBatis generator配置 overwrite 文件覆盖失效
工具:IDEA.jdk1.8.mysql 底部有解决方法! pom.xml配置 <plugins> <!--Mybatis自动代码插入--> <plugin> &l ...
- MyBatis:Mybatis逆向工程问题记录
近日我在搭建springboot+mybatis+mysql 的整合项目(自己测试玩)的时候用到了mybatis的逆向工程,来这里记录一下我的菜鸟编码过程 首先我在maven中引入这些依赖 <d ...
- 【分享】标准springMVC+mybatis项目maven搭建最精简教程
文章由来:公司有个实习同学需要做毕业设计,不会搭建环境,我就代劳了,顺便分享给刚入门的小伙伴,我是自学的JAVA,所以我懂的.... (大图直接观看显示很模糊,请在图片上点击右键然后在新窗口打开看) ...
- Java MyBatis 插入数据库返回主键
最近在搞一个电商系统中由于业务需求,需要在插入一条产品信息后返回产品Id,刚开始遇到一些坑,这里做下笔记,以防今后忘记. 类似下面这段代码一样获取插入后的主键 User user = new User ...
- [原创]mybatis中整合ehcache缓存框架的使用
mybatis整合ehcache缓存框架的使用 mybaits的二级缓存是mapper范围级别,除了在SqlMapConfig.xml设置二级缓存的总开关,还要在具体的mapper.xml中开启二级缓 ...
- 【SSM框架】Spring + Springmvc + Mybatis 基本框架搭建集成教程
本文将讲解SSM框架的基本搭建集成,并有一个简单demo案例 说明:1.本文暂未使用maven集成,jar包需要手动导入. 2.本文为基础教程,大神切勿见笑. 3.如果对您学习有帮助,欢迎各种转载,注 ...
- mybatis plugins实现项目【全局】读写分离
在之前的文章中讲述过数据库主从同步和通过注解来为部分方法切换数据源实现读写分离 注解实现读写分离: http://www.cnblogs.com/xiaochangwei/p/4961807.html ...
- MyBatis基础入门--知识点总结
对原生态jdbc程序的问题总结 下面是一个传统的jdbc连接oracle数据库的标准代码: public static void main(String[] args) throws Exceptio ...
随机推荐
- JEECMS自定义标签开发步骤
JEECMS自带的只有[@cms_advertising]标签,并且官方没有给文档,用法: [@cms_advertising id='3'] <img src=&quo ...
- div代码大全 DIV代码使用说明
一.DIV代码语法 - TOP DIV代码是放入小于与大于符号内,即“<div>”. DIV是一对闭合标签,即“”开始,“结束”的盒子标签. 语法结构: <div>我是内容&l ...
- FreeMarker 获取页面request、session
使用Request里的Attribute值最简单的方法就是直接${AttributeName}或者安全一点:${AttributeName!"default Value"} 1.取 ...
- oracle习题集-高级查询
1.问题:查询每个员工的部门名称,列出员工姓名和部门名称 select e.ename,d.dname from emp e,dept d where e.deptno=d.deptno 2. 问题: ...
- JQMObile 优势
1.跨平台 目前大部分的移动设备浏览器都支持HTML5标准,jQuery Mobile以HTML5标记配置网页,所以可以跨不同的移动设备,如Apple iOS,Android,BlackBerry, ...
- Codevs1922 骑士共存问题
1922 骑士共存问题 题目描述 Description 在一个n*n个方格的国际象棋棋盘上,马(骑士)可以攻击的棋盘方格如图所示.棋盘上某些方格设置了障碍,骑士不得进入. 对于给定的n*n个方格的国 ...
- Leetcode36.Valid Sudoku有效的数独
判断一个 9x9 的数独是否有效.只需要根据以下规则,验证已经填入的数字是否有效即可. 数字 1-9 在每一行只能出现一次. 数字 1-9 在每一列只能出现一次. 数字 1-9 在每一个以粗实线分隔的 ...
- 当移动数据分析需求遇到Quick BI
我叫洞幺,是一名大型婚恋网站“我在这等你”的资深老员工,虽然在公司五六年,还在一线搬砖.“我在这等你”成立15年,目前积累注册用户高达2亿多,在我们网站成功牵手的用户达2千多万.目前我们的公司在CEO ...
- webpack学习之——npm的安装依赖情况
这几天一直在研究webpack模块话打包工具,在网上的资源还是蛮丰富的,现在总结下这块的内容,需要好好的研究下,如果有问题,还请指正. 先是第一个为问题,就是npm-install --save 和n ...
- C++ UNREFERENCED_PARAMETER函数的作用
新建win32 application程序,会有这样一段代码 int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hP ...