mybatis generator 使用方法
环境: ubuntu eclipse maven
一. 简介
mybatis-geneator是一款mybatis自动代码生成工具,可以通过配置,快速生成mapper和xml文件以及pojo
二.配置
pom.xml配置
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.7</version>
</dependency>
</dependencies> <build>
<finalName>shop</finalName>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugin>
</plugins>
</build>
在main的resource目录下创建generatorConfig.xml文件

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"> <!-- classPath:数据库的JDBC驱动-->
<generatorConfiguration>
<classPathEntry
location="/home/jiang/.m2/repository/mysql/mysql-connector-java/8.0.16/mysql-connector-java-8.0.16.jar"/>
<context id="default" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressDate" value="false"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator> <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://106.13.46.152:3306/shop" userId="jiang"
password="1"/> <javaModelGenerator targetPackage="com.feilong.shop.entity"
targetProject="./src/main/java">
<!-- TODO enableSubPackages:是否让schema作为包的后缀-->
<property name="enableSubPackages" value="false"/>
<!-- 从数据库返回的值被清理前后的空格-->
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--map xml生成器 -->
<sqlMapGenerator targetPackage="com.feilong.shop.dao.mappers"
targetProject="./src/main/java">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator>
<!-- dao生成器-->
<javaClientGenerator targetPackage="com.feilong.shop.dao"
targetProject="./src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator> <!-- 数据表与Bean的映射 -->
<table tableName="shop_user" domainObjectName="User" >
<!-- 如果设置为true,生成的model类会直接使用column本身的名字,而不会再使用驼峰命名方法,比如BORN_DATE,生成的属性名字就是BORN_DATE,而不会是bornDate -->
<property name="useActualColumnNames" value="true"/>
</table>
<table tableName="shop_address" domainObjectName="Address" >
<property name="useActualColumnNames" value="true"/>
</table> <table tableName="shop_cart" domainObjectName="Cart" >
<property name="useActualColumnNames" value="true"/>
</table>
<table tableName="shop_category" domainObjectName="Category" >
<property name="useActualColumnNames" value="true"/>
</table> <table tableName="shop_comment" domainObjectName="Comment" >
<property name="useActualColumnNames" value="true"/>
</table> <table tableName="shop_goods" domainObjectName="Goods" >
<property name="useActualColumnNames" value="true"/>
</table>
<table tableName="shop_order" domainObjectName="Order" >
<property name="useActualColumnNames" value="true"/>
</table>
<table tableName="shop_orderdetail" domainObjectName="OrderDetail" >
<property name="useActualColumnNames" value="true"/>
</table>
<table tableName="shop_orderstatus" domainObjectName="OrderStatus" >
<property name="useActualColumnNames" value="true"/>
</table>
<table tableName="visit" domainObjectName="Visit" >
<property name="useActualColumnNames" value="true"/>
</table> </context>
</generatorConfiguration>
三. 生成文件
linux控制台在项目pom.xml配置文件的同级目录下输入
mvn mybatis-generator:generate
mybatis generator 使用方法的更多相关文章
- Mybatis Generator自动生成的mapper只有insert方法
– Mybatis Generator 生成的mapper只有insert方法 – 首先检查generatorConfig.xml中table项中的属性 enableSelectByPrimaryKe ...
- Mybatis Generator的model生成中文注释,支持oracle和mysql(通过实现CommentGenerator接口的方法来实现)
自己手动实现的前提,对maven项目有基本的了解,在本地成功搭建了maven环境,可以参考我之前的文章:maven环境搭建 项目里新建表时model,mapper以及mapper.xml基本都是用My ...
- mybatis generator自动生成sqlmap代码的不完善之处以及解决方法
a) 建表时,字段名称建议用"_"分隔多个单词,比如:AWB_NO.REC_ID...,这样生成的entity,属性名称就会变成漂亮的驼峰命名,即:awbNo.recId b)or ...
- Mybatis—三剑客之generator使用方法
三剑客之generator主要用于自动生成POJO实体类 准备素材: mybatis-generator-core-1.3.2.jar mysql-connector-java-5.1.2 ...
- mybatis Generator生成代码及使用方式
本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5889312.html 为什么要有mybatis mybatis 是一个 Java 的 ORM 框架,OR ...
- mybatis generator 自动生成dao层映射代码
资源: doc url :http://www.mybatis.org/generator/ download:https://github.com/mybatis/generator/release ...
- MyBatis Generator作为maven插件自动生成增删改查代码及配置文件例子
什么是MyBatis Generator MyBatis Generator (MBG) 是一个Mybatis的代码生成器,可以自动生成一些简单的CRUD(插入,查询,更新,删除)操作代码,model ...
- Mybatis Generator生成工具配置文件详解
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration ...
- MyBatis Generator 详解
MyBatis Generator中文文档 MyBatis Generator中文文档地址:http://mbg.cndocs.tk/ 该中文文档由于尽可能和原文内容一致,所以有些地方如果不熟悉,看中 ...
随机推荐
- html中 的method=post和method=get的区别
1. get是从服务器上获取数据,post是向服务器传送数据. 2. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到.post是通过 ...
- 微信小程序中显示html富文本的方法
微信小程序中显示html富文本的方法 使用方法:git地址:https://github.com/icindy/wxParse 一.下载wxParse文件 二.在要引入的页面的js文件中,引入文件 j ...
- sql 2008常用语法语句收集
EXEC sp_dropuser 'test' : 从当前数据库删除用户 test EXEC sp_droplogin 'test' : 从 SQL Server 中删除登录 test select ...
- PCB学习
一.PCB设置 在线DRC:自动更正,会提示短路. 对象捕捉>>智能元件snap,可以智能抓取中心点,勾选 智能TrackEnds: 撤销重做:30步 旋转步骤:90.000(可以按空格旋 ...
- codeforces798C - Mike and gcd problem (数论+思维)
原题链接:http://codeforces.com/contest/798/problem/C 题意:有一个数列A,gcd(a1,a2,a3...,an)>1 时称这个数列是“漂亮”的.存在这 ...
- 【2019 Multi-University Training Contest 3】
01: 02:https://www.cnblogs.com/myx12345/p/11593829.html 03: 04:https://www.cnblogs.com/myx12345/p/11 ...
- flutte页面布局四
AspectRatio 组件 AspectRatio 的作用是根据设置调整子元素 child 的宽高比. AspectRatio 首先会在布局限制条件允许的范围内尽可能的扩展,widget 的高度是由 ...
- PyQuery爬取历史天气信息
1.准备工作: 网址:https://lishi.tianqi.com/xian/index.html 爬虫类库:PyQuery,requests 2.网页分析: 红线部分可更改为需要爬取的城市名,如 ...
- B-Tree, B+Tree, B*树介绍
[数据结构]B-Tree, B+Tree, B*树介绍 转 [数据结构]B-Tree, B+Tree, B*树介绍 [摘要] 最近在看Mysql的存储引擎中索引的优化,神马是索引,支持啥索引.全是 ...
- nRF51822 之 Interrupt
nRF51822的中断使用在官方的例程中好像没有!