源码链接: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. 全网最全RabbitMQ总结,别再说你不会RabbitMQ

    RabbitMQ入门教程 当初我学RabbitMQ的时候,第一时间就上GitHub找相应的教程,但是令我很失望的是没有找到,Spring,Mybatis之类的教程很多,而RabbitMQ的教程几乎找不 ...

  2. Java入门 - 语言基础 - 19.方法

    原文地址:http://www.work100.net/training/java-method.html 更多教程:光束云 - 免费课程 方法 序号 文内章节 视频 1 概述 2 方法的定义 3 方 ...

  3. 异数OS国产CPU平台移植项目需求分析

    异数OS国产CPU平台移植项目需求分析 目录 异数OS国产CPU平台移植项目需求分析 项目立项背景 项目需求分析 异数OS性能指标简介 1.TCP协议栈性能测试 2.异数OS-织梦师-水母 消息队列性 ...

  4. [bzoj3529] [洛谷P3312] [Sdoi2014] 数表

    Description 有一张n×m的数表,其第i行第j列(1 < =i < =n,1 < =j < =m)的数值为 能同时整除i和j的所有自然数之和.给定a,计算数表中不大于 ...

  5. Easy C 编程 in Linux

    入坑Ubuntu有4,5天了,当时各种不习惯,但现在渐渐喜欢上了这种简单大方的显示界面和快速高效的命令行模式,各种没有的功能也都有网页版,非常不错呢. 现在最让我感到神奇之处,便是Linux的C编程是 ...

  6. HTML中CSS引用——选择器的使用

    一.元素选择器     1.书写格式:标记名{/*生命块*/}     2.所有与该标记匹配的元素,都将应用声明块中的规则 二.类选择器     1.书写格式:.类名{/*声明块*/}         ...

  7. PlayCanvas PBR材质shader代码分析(vertex shader)

    顶点shader主要对顶点坐标变换,将顶点坐标从local->world->view->clip 空间变换 local空间:模型物体坐标系 world空间:世界空间坐标系 view空 ...

  8. PYTHON经典算法-完美平方

    问题描述: 给定一个正整数n,找到若干个完全平方数(例如:1,4,9),使得 它们的和等于n,完全平方数的个数最少. 问题示例: 给出n=12,返回3,因为12=4+4+4:给出n=13,返回2,因为 ...

  9. 21种JavaScript设计模式最新记录(含图和示例)

    最近观看了<Javascript设计模式系统讲解与应用>教程,对设计模式有了新的认识,特在此做些记录. 一.UML 文中会涉及众多的UML类图,在开篇需要做点基础概念的认识.以下面的图为例 ...

  10. SpringBoot学习(1) - 日志

    package com.study.spring_boot_log; import org.springframework.boot.SpringApplication; import org.spr ...