【Java MyBatis Generator】使用generator自动生成Dao,Mapping和实体文件
具体请参照:
http://blog.csdn.net/fengshizty/article/details/43086833
按照上面博客地址,下载Generator的依赖包:
如下是我的配置文件:
<?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="C:\Generate\generator\generator\mysql-connector-java-5.1.34.jar" />
<!-- <classPathEntry location="C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar" />-->
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 数据库链接URL、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/testmybatis" userId="root" password="XXXXX">
<!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa">-->
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="com.zlg.model" targetProject="C:\Generate\generator\generator\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成的映射文件包名和位置 -->
<sqlMapGenerator targetPackage="com.zlg.mapping" targetProject="C:\Generate\generator\generator\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.zlg.dao" targetProject="C:\Generate\generator\generator\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
<table tableName="user" domainObjectName="UserInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="dept" domainObjectName="DeptInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="emp" domainObjectName="EmpInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="cost" domainObjectName="CostInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
</context>
</generatorConfiguration>
根据以上配置文件中的标记位置,修改成你需要的位置,然后运行如下指令(记住用tab键补全命令,这个用过CMD或者Linux都知道)。

运行成功后,就生成了如下文件:

当然,如果你比较懒,可以直接把生成路径设置成你项目的相应位置。
此时,你就可以把这些对应的文件拷贝到项目的相关位置了。非常简单,而且以上链接的作者已经写得很详细了。
感谢分享~
【Java MyBatis Generator】使用generator自动生成Dao,Mapping和实体文件的更多相关文章
- idea集成 MyBatis Generator 插件,自动生成dao,model,sql map文件
1.集成到开发环境中 以maven管理的功能来举例,只需要将插件添加到pom.xml文件中即可.(注意此处是以plugin的方式,放在<plugins></plugins>中间 ...
- 使用mybatis generator插件,自动生成dao、dto、mapper等文件
mybatis generator 介绍 mybatis generator中文文档http://mbg.cndocs.tk/ MyBatis Generator (MBG) 是一个Mybatis的代 ...
- mybatis-generator自动生成dao,mapping,model
mybatis-generator下载地址:https://github.com/mybatis/generator/releases/tag/mybatis-generator-1.3.2 下载好后 ...
- java web(七): mybatis的动态sql和mybatis generator自动生成pojo类和映射文件
前言: MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其它类似框架的经验,你就能体会到根据 不同条件拼接 SQL 语句的痛苦.例如拼接时要确保不能忘记添加必要的空格,还 ...
- mybatis generator cmd 终端命令 生成dao model mapper
mybatis generator cmd 终端命令 生成dao model mapper 文件包下载 mybatis-generator-core-1.3.2.jar 下载地址:https://gi ...
- Mybatis-Generator 自动生成Dao、Model、Mapping相关文档
最近在学习mybatis,结果在写Mapping的映射文件时insert语句一直报错,于是想看看标准的映射文件是什么样.百度到Mybatis-Generator 自动生成Dao.Model.Mappi ...
- Mybatis-Generator插件自动生成Dao、Model、Mapping相关文件
最近做项目,mapping 有点多而且容易写错,于是试着用了Mybatis-Generator 插件自动生成 dao, domain mapping 文件.感觉还挺好用.把相关配置分享,一边以后做项 ...
- Mybatis最入门---代码自动生成(generatorConfig.xml配置)
[一步是咫尺,一步即天涯] 经过前文的叙述,各位看官是不是已经被Mybatis的强大功能给折服了呢?本文我们将介绍一个能够极大提升我们开发效率的插件:即代码自动生成.这里的代码自动生成包括,与数据库一 ...
- IDEA利用mybatis-generator自动生成dao和mapper
pom.xml配置 <properties> <java.version>1.8</java.version> <mybatis-generator-core ...
- Mybatis-Generator自动生成Dao、Model、Mapping等相关映射文件(懒人版)
今天在学习mybatis生成相关的映射文件的时候,发现了往期的生成Dao.Model.Mapping等文章多数都是一样的,我也在学着重复造轮子,不过是懒人造的.本文旨在解决开发过程,简化配置文件的“手 ...
随机推荐
- angularjs学习笔记—工具方法
angular.bind(self, fn, args) 作用:返回一个新的函数,绑定这个函数的this指向self 参数: self:新函数的上下文对象 fn:需要绑定的函数 args:传递给函数的 ...
- nginx配置图片防盗链
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)${ expires 30d; access_log off; valid_referers none blocked ...
- Microsoft.Web.Redis.RedisSessionStateProvider
https://github.com/Azure/aspnet-redis-providers https://www.nuget.org/packages/Microsoft.Web.RedisSe ...
- C语言中的参数传递
有空看看: c语言 函数传输传递的三种方式(值.指针.引用) C语言之参数传递 C语言形参和实参,传值调用和引用调用的区别
- css3d总结
3d舞台 设置 perspective(景深): length, 可以设置overflow:hidden 3d舞台下 -> 3d元素容器 设置 transform-style: preserv ...
- sqlserver2008 R2 创建作业(定时任务)
如题: 第一步: 第二步: 第三步: 第四步: 第五步: 第六步: 第七步: 完成!!! 记得把服务打开.设置为自动启动,别重启服务器后没用了.
- 【转】跟我学Kafka之NIO通信机制
from:云栖社区 玛德,今天又被人打脸了,小看人,艹,确实,相对比起来,在某些方面差一点,,,,该好好捋捋了,强化下短板,规划下日程,,,引以为耻,铭记于心. 跟我学Kafka之NIO通信机制 ...
- Linux平台延时之sleep、usleep、nanosleep、select比较
Linux平台延时之sleep.usleep.nanosleep.select比较 标签: 嵌入式thread线程cpu多线程 2015-05-05 15:28 369人阅读 评论(0) 收藏 举报 ...
- vim基础命令
2015-06-04 by komilevim基础命令 打开一个文件 vim index.php 几种模式说明Normal Mode也就是最一般的普通模式,默认进入vim之后,处于这种模式.Inser ...
- systemd
本文参照:https://wiki.archlinux.org/index.php/Systemd#Basic_systemctl_usage 做了翻译和整理 systemd是Linux下的一种ini ...