一、简介

简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器,可以快速的根据表生成对应的映射文件,接口,以及bean类。

支持基本的增删改查,以及QBC风格的条件查询。

但是表连接、存储过程等这些复杂sql的定义需要我们手工编写

• 官方文档地址 http://www.mybatis.org/generator/

• 官方工程地址 https://github.com/mybatis/generator/releases

2.1、依赖

  <dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>

2.2添加插件: 里面还要在添加一个mysql连接驱动的依赖 。

   <!--mybatis-generator-maven-plugin-->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.32</version>
</dependency>
</dependencies>
</plugin>

2.3在resources源文件夹下面创建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>
<!-- <classPathEntry location="D:/Java/lib/mysql-connector-java-5.1.43.jar" />-->
<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>
<commentGenerator>
<!-- 这个元素用来去除指定生成的注释中是否包含生成的日期 false:表示保护 -->
<!-- 如果生成日期,会造成即使修改一个字段,整个实体类所有属性都会发生变化,不利于版本控制,所以设置为true -->
<property name="suppressDate" value="true" />
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--数据库链接URL,用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/crmpro"
userId="root"
password="ych521mm">
</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>
<!-- 指定javaBean的生成策略 文件夹自己定义-->
<javaModelGenerator targetPackage="pojo"
targetProject=".\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator> <!-- sqlMapGenerator:sql映射生成策略: -->
<sqlMapGenerator targetPackage="dao"
targetProject=".\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator> <!-- javaClientGenerator:指定mapper接口所在的位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="dao"
targetProject=".\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator> <!-- 指定要逆向分析哪些表:根据表要创建javaBean -->
<table tableName="account" domainObjectName="Account"></table> <!-- 要生成哪些表 -->
<table tableName="employee" domainObjectName="Employee"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table> </context>
</generatorConfiguration>

这样就在idea搭配maven环境下完成代码的生成!!!!

ideamaven版的MBG逆向工程的更多相关文章

  1. Mybatis七(MBG 逆向工程)

    官方地址:http://www.mybatis.org/generator/ https://github.com/mybatis/generator/releases <1>编写mbg. ...

  2. MyBatis_Generator (MBG)逆向工程的四种方式

    mybatis是目前很流行的持久层框架,其逆向工程更是大大缩减了我们的开发时间.有兴趣的可以看文档. 文档地址: http://www.mybatis.org/generator/index.html ...

  3. MBG逆向工程报错:generate failed: Exception getting JDBC Driver: com.mysql.jdbc.Driver

    修改pom文件,逆向工程如下: <!-- 逆向工程 --> <plugin> <groupId>org.mybatis.generator</groupId& ...

  4. 回顾一下MyBatis逆向工程——自动生成代码

    前言 最近做的项目(SSM+Shiro)的数据库表已经创建完成,一共有15张表,如果我们一个个去写pojo/bean的代码以及各种sql语句的话未免太过麻烦而且很容易出错,这个时候我们就需要MyBat ...

  5. 尚硅谷SSM-CRUD实战Demo

    SSM-CRUD实战项目 1. 项目总览 SpringMVC + Spring + MyBatis CRUD:增删改查 功能: 分页 数据校验 jquery前端校验+JSR303后端校验 ajax R ...

  6. 01_Mybaits逆向工程maven版

    1.创建generatorSqlmapCustom工程 2.修改pom文件 <?xml version="1.0" encoding="UTF-8"?&g ...

  7. mybatis逆向工程mbg

    mbg:mybatis generator=mybatis代码生成器 1.看一下项目结构 其中bean文件,mapper接口文件和mapper.xml文件是代码生成器自动生成的. 使用generato ...

  8. IntelliJ IDEA 2017版 spring-boot2.0.4+mybatis反向工程;mybatis+springboot逆向工程

    一.搭建环境 采用IDE自动建立项目方式 然后,next next,配置导入依赖包 项目就生成了,在项目下导入配置文件GeneratorMapper.xml(项目结构如图所示) 配置文档,建立数据库和 ...

  9. mybatis逆向工程 mbg运行java代码时提示找不到MBG.xml的解决方法

    这里要写全路径才能找到文件

随机推荐

  1. Leetcode 14. Longest Common Prefix(水)

    14. Longest Common Prefix Easy Write a function to find the longest common prefix string amongst an ...

  2. OpenCV Machine Learning (C++)

    /*M/////////////////////////////////////////////////////////////////////////////////////////// IMPOR ...

  3. Fiddler抓取手机Https请求

    下载并安装Fiddler证书生成器 1.打开Fiddler—>Tools—>Telerik Fiddler Options... 2.Connections选项中勾选Allow remot ...

  4. ES的聚合操作

    构建数据: ​    @Test    public void createIndex(){        /**         * 创建索引         * */        client. ...

  5. linux 文件相关常用命令

    文件或者目录操控命令 1,cd切换目录. 其中- 代表前一个目录 2,mkdir 新建目录. 加上-p参数可以递归创建多级目录 mkdir -p test1/test2/test3 3,rmdir删除 ...

  6. onchange and oninput

    https://www.w3schools.com/jsref/event_oninput.asp Supported HTML tags: <input type="color&qu ...

  7. HTML转换PDF及SWF及图片

    一.源码特点        在一些应用场景中,出于某些目的(例如需要对文章内容进行保护,禁止用户真接复制文字内容),不能直接提供HTML的方式进行浏览,那么就需要将文章内容转换为其它的格式如PDF.图 ...

  8. linux让命令或程序在终端后台运行的方法(Ubuntu/Fedora/Centos等一样适用)

    https://segmentfault.com/a/1190000008314935

  9. ssh连接MAC服务器显示No route to host解决方法

    首先MAC操作系统是10 其它电脑通过ssh访问一台mac服务器时,有时候可以登录进去,有显示显示no route to host 并且通过浏览器访问布署在mac上的jenkins,反应奇慢,后来做了 ...

  10. 爬虫解析库xpath

    # xpath简介 XPath即为XML路径语言(XML Path Language),它是一种用来确定XML文档中某部分位置的语言.用于在 XML 文档中通过元素和属性进行导航. XPath基于XM ...