1. 今天给大家介绍在 spring- boot 项目中如何使用 maven 插件逆向工程生成 Mybatis 代码。

    pom.xml 添加依赖和插件

    <dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.3.0</version>
    </dependency> <build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    <plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.2</version>
    <configuration>
    <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
    <overwrite>true</overwrite>
    <verbose>true</verbose>
    </configuration>
    <dependencies>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.29</version>
    <scope>runtime</scope>
    </dependency>
    </dependencies>
    </plugin>
    <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.2</version>
    <executions>
    <execution>
    <id>pre-test</id>
    <goals>
    <goal>prepare-agent</goal>
    </goals>
    </execution>
    <execution>
    <id>pre-test</id>
    <phase>test</phase>
    <goals>
    <goal>report</goal>
    </goals>
    </execution>
    <execution>
    <id>post-test-aggregate</id>
    <phase>test</phase>
    <goals>
    <goal>report-aggregate</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    </plugins>
    </build>

    上图还配置了 jacoco 插件,为了使用看代码单元测试的覆盖率,不需要的同学可以去掉此插件。

    在 resources 根目录下创建 generator 文件夹,再在此文件夹下创建 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="DB2Tables" targetRuntime="MyBatis3">
    <commentGenerator>
    <property name="suppressDate" value="true"/>
    <!-- 是否去除自动生成的注释 -->
    <property name="suppressAllComments" value="true"/>
    </commentGenerator>
    <!--数据库链接信息 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
    connectionURL="jdbc:mysql://localhost:3306/parse_json"
    userId="root"
    password="root">
    </jdbcConnection>
    <javaTypeResolver>
    <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
    <property name="forceBigDecimals" value="false"/>
    </javaTypeResolver>
    <!-- 生成实体类的包名和位置 ,targetPackage指的是包名,targetProject值得是路径位置-->
    <javaModelGenerator targetPackage="com.rookie.model" targetProject="src/main/java">
    <property name="enableSubPackages" value="true"/>
    <property name="trimStrings" value="true"/>
    </javaModelGenerator>
    <!-- 生成映射文件的包名和位置-->
    <sqlMapGenerator targetPackage="main.resources.com.rookie.mapper" targetProject="src">
    <property name="enableSubPackages" value="true"/>
    </sqlMapGenerator>
    <!-- 生成DAO的包名和位置-->
    <javaClientGenerator type="XMLMAPPER" targetPackage="com.rookie.mapper" targetProject="src/main/java">
    <property name="enableSubPackages" value="true"/>
    </javaClientGenerator>
    <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
    <table tableName="input_file_path" domainObjectName="FilePathDO"
    enableCountByExample="false" enableUpdateByExample="false"
    enableDeleteByExample="false" enableSelectByExample="false"
    selectByExampleQueryId="false">
    </table>
    </context>
    </generatorConfiguration>
  2. 项目结构如图。按照如图所示,点击插件生成即可。

SpringBoot 之 Mybatis 逆向工程的更多相关文章

  1. springboot中mybatis逆向工程与分页的应用

    最近在项目中应用到springboot与mybatis,在进行整合过程中遇到一些坑,在此将其整理出来,便于以后查阅与复习. 项目运行环境为:eclispe+jdk1.8+maven 一.搭建Sprin ...

  2. SpringBoot 3.SpringBoot 整合 MyBatis 逆向工程以及 MyBatis 通用 Mapper

    一.添加所需依赖,当前完整的pom文件如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&qu ...

  3. springboot集成mybatis(逆向工程),热部署以及整合Swagger2

    本文是作者原创,版权归作者所有.若要转载,请注明出处. springboot集成mybatis和mybatis-generator插件 1.新建Springboot项目(略) 2.导入相关依赖 < ...

  4. Springboot的Mybatis逆向工程

    1.pom.xml添加mybatis和逆向插件依赖: <dependency> <groupId>org.mybatis.spring.boot</groupId> ...

  5. idea+springboot+mybatis逆向工程

    前提:使用idea开发,基于springboot.用到了mybatis的逆向工程 因为之前用eclipse开发ssm比较多,现在转idea 使用springboot 踩了一些坑,在这记录一下~ 注意事 ...

  6. SpringBoot (四) - 整合Mybatis,逆向工程,JPA

    1.SpringBoot整合MyBatis 1.1 application.yml # 数据源配置 spring: datasource: driver-class-name: com.mysql.c ...

  7. springboot整合mybatis增删改查(三):mybatis逆向工程

    上一篇已经把项目基本框架完善,接下来就是利用Mybatis Generator逆向工程进行mybatis的整合. 我们在创建项目开始的时候已经勾选web,mybatis,sql等,但是这些依赖还是不够 ...

  8. SpringBoot系列——MyBatis整合

    前言 MyBatis官网:http://www.mybatis.org/mybatis-3/zh/index.html 本文记录springboot与mybatis的整合实例:1.以注解方式:2.手写 ...

  9. mybatis逆向工程(MyBatis Generator)

    mybatis逆向工程(MyBatis Generator) 1. 什么是mybatis逆向工程 mybatis官方为了提高开发效率,提高自动对单表生成sql,包括 :mapper.xml.mappe ...

随机推荐

  1. KiCAD的一些快捷操作(类比于AD)

    一.原理图快捷操作 二.PCB快捷操作 Q: 在布线过程中,用来编辑线宽,和AD中布线时“Tab”的作用相似 W: 选择设定好的线宽,线宽减小 Shift+W: 选择设定好的线宽,线宽变大 /: 改变 ...

  2. 小米手机 - Charles无法安装证书 因为无法读取证书

    1.不要使用小米原装的浏览器安装证书 2.使用第三方浏览器安装,如我使用的是UC浏览器 3.使用第三方浏览器安装的证书格式是".pem"格式问卷 4.将这个文件放入小米的downl ...

  3. Gym 102007I 二分 网络流

    题意:给你一张图,每个城市有一些人,有不超过10个城市有避难所,避难所有容量上限,问最快多久可以让所有人进入避难所? 思路:二分时间,对于每个时间跑一遍最大流,判断最大流是不是人数即可.我们还需要用二 ...

  4. 一些笔记jexcel

    根据坐标或者指定列标题 jexcel.getColumnNameFromId([ x, y ]);

  5. 从 Server Timing Header 看服务器是如何处理请求的

    原文作者:Florian Hämmerle      译者:UC 国际研发 Jothy   写在最前:欢迎你来到“UC国际技术”公众号,我们将为大家提供与客户端.服务端.算法.测试.数据.前端等相关的 ...

  6. css样式重叠、css样式继承、css 属性计算,,a元素下的文字颜色不能继承

    1.属性的重叠 在渲染前浏览器将判断使用哪个样式 我们书写的样式会覆盖浏览器的自带样式 我们写的样式进行权重比较,规则如下 !import Infiniti无穷大 进制伪256行内样式 1000.id ...

  7. 关于_getattr_方法的一些理解

    在学习rest framework的过程中,rest framework的request是经过重构的,但是如果调用重构对象request中的属性,如果属性不存在会调用原request对象中的属性,它使 ...

  8. ansible如何用root用户运行普通用户授权

    ansible默认以root用户进行授权,但是需要用普通用户执行一些命令操作: 如: 1. ansible 10.0.0.1 -m raw -a "date" -u www 但是会 ...

  9. [人物存档]【AI少女】【捏脸数据】朴素风格

    点击下载(城通网盘):AISChaF_20191115113752642.png 点击下载(城通网盘):AISChaF_20191111232359711.png

  10. luoguP2590 [ZJOI2008]树的统计 [树链剖分] [TLE的LCT]

    题目描述 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w. 我们将以下面的形式来要求你对这棵树完成一些操作: I. CHANGE u t : 把结点u的权值改为t II. QMAX u ...