源码链接:https://pan.baidu.com/s/1iP4UguBufHbcIEv4Ux4wDw

提取码:j6z9

目录结构如下:只需增加一个generatorConfig.xml文件和在pom.xml中配置下Mybatis generator代码生成插件即可

pom.xml中增加如下配置:

pom.xml中相关依赖及build插件部分代码

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies> <build>
<!-- maven工程在默认情况下src/main/java目录下的mapper文件是不发布到target目录下的 -->
<!-- 增加下面resource配置将resources目录下的文件和java目录下的配置文件添加资源映射-->
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- Mybatis generator代码生成插件 配置 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.1</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>

generatorConfig.xml文件内容如下:

<!--数据库驱动包路径 -->
<classPathEntry location="C:\Users\heave\.m2\repository\mysql\mysql-connector-java\5.1.30\mysql-connector-java-5.1.30.jar"/> <context id="DB2Tables" targetRuntime="MyBatis3">
<!--关闭注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator> <!--数据库连接信息 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/big_strong?characterEncoding=utf-8"
userId="root" password="123456">
</jdbcConnection> <!--生成的model 包路径 -->
<javaModelGenerator targetPackage="big.strong.disheng.user.model" targetProject="src/main/java">
<property name="enableSubPackages" value="ture"/>
<property name="trimStrings" value="false"/>
</javaModelGenerator> <!--生成xml mapper文件 路径 -->
<sqlMapGenerator targetPackage="big.strong.disheng.user.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="ture"/>
</sqlMapGenerator> <!-- 生成的Dao接口 的包路径 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="big.strong.disheng.user.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="ture"/>
</javaClientGenerator>
<!--对应数据库表名 tableName数据库表名称,domainObjectName生成model类的名称 -->
<table tableName="role" domainObjectName="Role" enableCountByExample="false"
enableSelectByExample="false" enableUpdateByExample="false" enableDeleteByExample="false">
<property name="useActualColumnNames" value="true"/>
</table>
<table tableName="permission" domainObjectName="Permission" enableCountByExample="false"
enableSelectByExample="false" enableUpdateByExample="false" enableDeleteByExample="false">
<property name="useActualColumnNames" value="true"/>
</table>
<table tableName="user_role" domainObjectName="UserRole" enableCountByExample="false"
enableSelectByExample="false" enableUpdateByExample="false" enableDeleteByExample="false">
<property name="useActualColumnNames" value="true"/>
</table>
<table tableName="role_permission" domainObjectName="RolePermission" enableCountByExample="false"
enableSelectByExample="false" enableUpdateByExample="false" enableDeleteByExample="false">
<property name="useActualColumnNames" value="true"/>
</table>
</context>

双击之后控制台会输出



完成

源码链接:https://pan.baidu.com/s/1iP4UguBufHbcIEv4Ux4wDw

提取码:j6z9

第二篇 Springboot mybatis generate根据数据库表自动生成实体类、Mapper和Mapper.xml的更多相关文章

  1. 根据数据库表自动生成实体类、xml和dao---mybatis

    网盘链接: https://pan.baidu.com/s/1AVGz0bDa_Y5zjk7vXa2eHw 提取码: 2gr6 1.记事本打开generatorConfig.xml文件 2(1,2,3 ...

  2. 使用mybatis-generator-core-1.3.2.jar根据数据库表自动生成实体

    1 导入mybatis-generator-core-1.3.2.jar 2配置mbg.xml <?xml version="1.0" encoding="UTF- ...

  3. MyBatis 逆向工程——根据数据表自动生成model、xml映射文件、mapper接口

    MyBatis Generator(MBG)的使用 MBG可以根据数据表生成对应的model.xml映射文件.mapper接口,只是简单的生成,还需要根据需求修改. 1.下载jar包 https:// ...

  4. mybits根据表自动生成 java类和mapper 文件

    mybits根据表自动生成 java类和mapper 文件 我这个脑子啊,每次创建新的工程都会忘记是怎么集成mybits怎么生成mapper文件的,so today , I can't write t ...

  5. Idea根据表自动生成实体

    Idea根据表自动生成实体: 首先说下这种方式有个缺点,就是如果表里面有日期.时间类型,那么需要手动的设置映射类型 第一步:在Idea中配置好数据库: 在Idea窗口右边,点击Database按钮 配 ...

  6. 使用.net core efcore根据数据库结构自动生成实体类

    源码 github,已更新最新代码 https://github.com/leoparddne/GenEntities/ 使用的DB是mysql,所有先nuget一下mysql.data 创建t4模板 ...

  7. 基于Dapper的开源Lambda扩展,且支持分库分表自动生成实体之基础介绍

    LnskyDB LnskyDB是基于Dapper的Lambda扩展,支持按时间分库分表,也可以自定义分库分表方法.而且可以T4生成实体类免去手写实体类的烦恼. 文档地址: https://lining ...

  8. SpringBoot整合Mybatis 使用generator自动生成实体类代码、Mapper代码、dao层代码

    1.新建一个SpringBoot项目,并引入Mybatis和mybatis-generator相关的依赖. <dependency> <groupId>org.springfr ...

  9. idea 根据数据库表自动创建持久化类

    一.点击最右边的Database: 二.点击,再点DataSource选择数据库类型,配置数据库信息: 三.打开项目结构,选择,找到你的项目,点击,添加hibernate: 四.如果有现成的cfg.x ...

随机推荐

  1. 2018徐州现场赛A

    题目链接:http://codeforces.com/gym/102012/problem/A 题目给出的算法跑出的数据是真的水 #include<iostream> #include&l ...

  2. python实现数据结构-栈

    注:本文档主要是学习<Python核心编程(第二版)>时的练习题. 栈是一种"后进先出"的数据结构(LIFO),是一种操作受限的线性结构,数据只能从栈顶进入和栈顶出去. ...

  3. Qt Installer Framework翻译(7-4)

    组件脚本 对于每个组件,您可以指定一个脚本,来准备要由安装程序执行的操作.脚本格式必须与QJSEngine兼容. 构造 脚本必须包含安装程序在加载脚本时创建的Component对象. 因此,脚本必须至 ...

  4. linux系统iot平台编程阶段总结

    1.inline内联函数 在C语言中,如果一些函数被频繁调用,不断地有函数入栈,即函数栈,会造成栈空间或栈内存的大量消耗. 为了解决这个问题,特别的引入了inline修饰符,表示为内联函数. 在使用循 ...

  5. jmeter连接数据库操作

    JDBC Connection Configuration 数据库连接配置 数据库连接配置器,用来连接数据库,是一个连接池. 界面介绍 1.右键线程组->添加->配置元件->JDBC ...

  6. html中如何清除浮动

    在html中,浮动可以说是比较常用的.在页面的布局中他有着很大的作用,但是浮动中存在的问题也是比较多的.现在我们简单说一下怎么去除浮动 首先我们先简单的看一下浮动: 首先我们先创建一个简单的div,并 ...

  7. 自定义BeanDefinitionRegistryPostProcessor注册bean

    自定义BeanDefinitionRegistryPostProcessor 概述 BeanDefinitionRegistryPostProcessor继承自BeanFactoryPostProce ...

  8. Docker底层架构之命名空间

    前言 命名空间是 Linux 内核一个强大的特性.每个容器都有自己单独的命名空间,运行在其中的 应用都像是在独立的操作系统中运行一样.命名空间保证了容器之间彼此互不影响.相应的命名空间功能如下: pi ...

  9. CORS解决跨域问题的几种方法

    一 后端服务器使用过滤器 新建过滤器: /** * 解决跨域 */ public class AccessControlAllowOriginFilter implements Filter { @O ...

  10. 机器学习:没有免费午餐定理(No Free Lunch Theorem)

    思考 机器学习中哪个算法好?哪个算法差呢? 下面两条线,哪个更好呢? 没有免费午餐定理 如果我们不对特征空间有先验假设,则所有算法的平均表现是一样的. 假设我们的计算机只有两个存储单元,而且每个存储单 ...