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/ 该中文文档由于尽可能和原文内容一致,所以有些地方如果不熟悉,看中 ...
随机推荐
- C++ 彩色图像(RGB)三通道直方图计算和绘制,图像逆时针旋转90° 实现代码
#include "iostream" #include "opencv2/opencv.hpp" #include "vector" us ...
- 报错——userdel: user hhh is currently used by process 9218
报错 userdel: user hhh is currently used by process 9218 [root@centos71 ~]# useradd hhh [root@centos71 ...
- Java反射学习-5 - 反射复制对象
通过反射方式复制对象: package cn.tx.reflect; import java.lang.reflect.Constructor; import java.lang.reflect.Fi ...
- paper 167:GPU的使用Theano之tutorial
Theano之使用GPU 英文版本:http://deeplearning.net/software/theano/tutorial/using_gpu.html using the ...
- intellijidea 设置字体等
http://blog.csdn.net/asmcvc/article/details/17144951 1.下载安装AndroidStudio:http://developer.android.co ...
- java并发编程笔记(六)——AQS
java并发编程笔记(六)--AQS 使用了Node实现FIFO(first in first out)队列,可以用于构建锁或者其他同步装置的基础框架 利用了一个int类型表示状态 使用方法是继承 子 ...
- spring boot 尚桂谷学习笔记09 数据访问
springboot 与数据库访问 jdbc, mybatis, spring data jpa, 1.jdbc原生访问 新建项目 使用 springboot 快速构建工具 选中 web 组件 sq ...
- 在WSL Ubuntu 下编译UPX详细步骤
准备环境: 1. sudo apt-get update 2. sudo apt-get clang 3. apt-get install libstdc++-dev Reading package ...
- Flink从socket读取数据sink到redis
package com.lin.flink.stream.customPartition; import org.apache.flink.api.common.functions.MapFuncti ...
- 美团2018年CodeM大赛-资格赛
https://www.nowcoder.com/acm/contest/138#question A.下单 水题…… B.可乐 题意:求期望 代码: #include<iostream> ...