这里只介绍mybatis generator生成代码

一、pom配置

在build-->plugins-->添加plugin

	<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.3</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.45</version>
</dependency>
</dependencies>
<configuration>
<!--配置文件的路径-->
<configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
</configuration>
</plugin>

二、编写 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">
<generatorConfiguration>
<context id="test" targetRuntime="MyBatis3">
<plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"></plugin>
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"></plugin>
<plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin">
<property name="searchString" value="DOExample$"/>
<property name="replaceString" value="Query"/>
</plugin>
<commentGenerator>
<!-- 这个元素用来去除指定生成的注释中是否包含生成的日期 false:表示保护 -->
<!-- 如果生成日期,会造成即使修改一个字段,整个实体类所有属性都会发生变化,不利于版本控制,所以设置为true -->
<property name="suppressDate" value="true" />
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="false" />
</commentGenerator>
<!--数据库链接URL,用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/mxntest" userId="root" password="root">
</jdbcConnection>
<javaTypeResolver>
<!-- This property is used to specify whether MyBatis Generator should
force the use of java.math.BigDecimal for DECIMAL and NUMERIC fields -->
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="com.example.demo.entity" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成映射文件的包名和位置 -->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.example.demo.dao"
targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator> <!-- 要生成哪些表 -->
<!--<table tableName="user" domainObjectName="user"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"></table>-->
<!--<table tableName="users" domainObjectName="UsersDO" />-->
<table tableName="save_record" domainObjectName="SaveRecordDO" />
</context>
</generatorConfiguration>

三、运行

  • 配置好插件

  • 配置好xml

  • xml对应的包创建好 一一对应

  • 运行方式

  • 目录结构

springboot 使用mybatis-generator自动生成代码的更多相关文章

  1. SpringBoot 添加mybatis generator 自动生成代码插件

    自动生成数据层代码,提高开发效率 1.pom添加插件,并指定配置文件路径 <!-- mybatis generator 自动生成代码插件 --> <plugin> <gr ...

  2. SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件

    原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...

  3. idea中mybatis generator自动生成代码配置 数据库是sqlserver

    好长时间没有写博客了,最近公司要用java语言,开始学习java,属于初学者,今天主要记录一下mybatis generator自动生成代码,首先在如下图的目录中新建两个文件,如下图 generato ...

  4. IDEA Maven Mybatis generator 自动生成代码

    IDEA Maven Mybatis generator 自动生成代码 一.安装配置maven以及在Idea中配置maven 安装过程步骤可以看上面的博文,里面介绍得很详细. 二.建数据表 DROP ...

  5. IDEA Maven Mybatis generator 自动生成代码(实例讲解)(转)

    IDEA Maven Mybatis generator 自动生成代码(实例讲解) MyBatis Generator • 简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器,可以快速的 ...

  6. 使用Mybatis Generator自动生成代码

    MyBatis Generator(MBG)是MyBatis MyBatis 和iBATIS的代码生成器.它将为所有版本的MyBatis以及版本2.2.0之后的iBATIS版本生成代码.它将内省数据库 ...

  7. Mybatis generator 自动生成代码(2)

    最近准备开始做一个项目,需要开始手动创建sql,于是将Mybatis generator 工具功能强化了下. 首先,这里引入到版本一点的包 <dependency> <groupId ...

  8. Mybatis generator 自动生成代码

    开发项目的时候,表很多,是不可能一点点的自己去写xml ,dao文件的,这里就需要用到代码的自动生成工具了. 第一步:导入jar包,当然,这之前,基本环境,像mybatis,数据库之类的都得搭建好. ...

  9. IDEA使用mybatis generator自动生成代码

    主要就三步: 1.pom 文件中引入jar包并配置 build 属性 <dependencies> <!-- 自动生产mapper Begin! --> <depende ...

  10. mybatis generator自动生成代码时 只生成了insert 而没有其他的

    mybatis框架提供了非常好用的逆向工程插件,但是在使用过程中会有很多问题. 我在使用中就遇到了只生成insert和insertSeletive方法,而不生成其他根据primary key查询更新删 ...

随机推荐

  1. django 本地项目部署uwsgi 以及云服务器部署 uwsgi+Nginx+Docker+MySQL主从

    一 .django 本地项目部署uwsgi 1 本地部署项目 uwsgi安装测试 通过uwsgi 进行简单部署 安装uwsgi命令:pip install uwsgi -i http://pypi.d ...

  2. day28 封装

    目录 一.什么是封装 二.将封装的属性进行隐藏操作 1 如何隐藏: 1.1 强行访问: 1.2 内部逻辑 三.为何要封装 一.什么是封装 封装是面向对象的三大特性中最核心的一个特性 封装<==& ...

  3. gulp-less打包后calc属性计算不准确的问题

    .step-item{ width: calc((100% - 50px) / 2); &:nth-child(2){ margin-right: 0; } } 这样直接写的话,编译时会直接给 ...

  4. redis(十七):Redis 安装,部署(WINDOWS环境下)

    1.下载Redis安装文件, 我选择的是 3.0.504 版本,有zip或msi可供下载.   2.解压缩后,打开安装目录 双击redis-server.exe启动redis服务器,双击redis-c ...

  5. 数据可视化之DAX篇(十五)Power BI按表筛选的思路

    https://zhuanlan.zhihu.com/p/121773967 ​数据分析就是筛选.分组.聚合的过程,关于筛选,可以按一个维度来筛选,也可以按多个维度筛选,还有种常见的方式是,利用几个特 ...

  6. Python之爬虫(十九) Scrapy框架中Download Middleware用法

    这篇文章中写了常用的下载中间件的用法和例子.Downloader Middleware处理的过程主要在调度器发送requests请求的时候以及网页将response结果返回给spiders的时候,所以 ...

  7. Json对象,Json数组,Json字符串的区别

    Json对象: var str = {"姓名":"张三","性别":"男","年龄":"2 ...

  8. HDFS+ClickHouse+Spark:从0到1实现一款轻量级大数据分析系统

    在产品精细化运营时代,经常会遇到产品增长问题:比如指标涨跌原因分析.版本迭代效果分析.运营活动效果分析等.这一类分析问题高频且具有较高时效性要求,然而在人力资源紧张情况,传统的数据分析模式难以满足.本 ...

  9. 【高性能Mysql 】读书笔记(二)

    第4章 Schema 与数据类型优化 本文为<高性能Mysql 第三版>第四章读书笔记,Mysql版本为5.5 选择优化的数据类型 选择合适数据类型的三个原则 更小的通常更好 - 速度更快 ...

  10. VMware虚拟机网络配置详解

    VMware网络配置:三种网络模式简介 安装好虚拟机以后,在网络连接里面可以看到多了两块网卡: 其中VMnet1是虚拟机Host-only模式的网络接口,VMnet8是NAT模式的网络接口,这些后面会 ...