创建 Maven 工程

网上有很多教程且 Idea 可以直接创建 这里就不进行

pom.xml 引入依赖和插件

pom中generalto-maven-plugs中必须指定mysql驱动,并且明确版本

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>top.orginly</groupId>
<artifactId>mall</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mall</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
<!-- mysql8 驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.24</version>
</dependency>
</dependencies> <build>
<plugins>
<!-- springboot的maven插件 -->
<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.4.0</version>
<configuration>
<!-- mybatis用于生成代码的配置文件 如果配置文件名为generatorConfig.xml 则不需要配置 -->
<!-- <configurationFile>src/main/resources/generator/generatorConfig.xml</configurationFile>-->
<!-- 允许移动生成的文件 -->
<verbose>true</verbose>
<!-- 启用覆盖 -->
<overwrite>true</overwrite>
</configuration>
<!-- 引入插件所需要的依赖 -->
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.24</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build> </project>

generatorConfig.xml 自动生成配置文件

table标签中需要指定tableName和生成的实体名字

<?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"/>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库链接地址账号密码-->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://172.17.0.2:3306/spring-boot-mall?useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=Asia/Shanghai"
userId="root"
password="000">
</jdbcConnection>
<javaTypeResolver>
<!--该属性可以控制是否强制DECIMAL和NUMERIC类型的字段转换为Java类型的java.math.BigDecimal,默认值为false,一般不需要配置。-->
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--生成Model类存放位置-->
<javaModelGenerator targetPackage="top.orginly.mall.model.pojo" targetProject="src/main/java">
<!--enableSubPackages:如果true,MBG会根据catalog和schema来生成子包。如果false就会直接用targetPackage属性。默认为false。-->
<property name="enableSubPackages" value="true"/>
<!--trimStrings:是否对数据库查询结果进行trim操作,如果设置为true就会生成类似这样public void setUsername(String username) {this.username = username == null ? null : username.trim();}的setter方法。默认值为false。-->
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--生成映射xml文件存放位置-->
<sqlMapGenerator targetPackage="mappers" targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!--生成Dao类存放位置(*Mapper.java)-->
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口
-->
<javaClientGenerator type="XMLMAPPER" targetPackage="top.orginly.mall.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator> <!--生成对应表及类名-->
<table tableName="mall_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<!--useActualColumnNames:如果设置为true,那么MBG会使用从数据库元数据获取的列名作为生成的实体对象的属性。 如果为false(默认值),MGB将会尝试将返回的名称转换为驼峰形式。 在这两种情况下,可以通过 元素显示指定,在这种情况下将会忽略这个(useActualColumnNames)属性。-->
<property name="useActualColumnNames" value="true"/>
<!-- 数据库表主键 可以不设置 -->
<generatedKey column="id" sqlStatement="Mysql" identity="true"/>
</table> </context>
</generatorConfiguration>

运行生成文件

这里推荐使用IDEA

我们只需要找到右边侧栏中的maven

依次找到 plugins–>mybatis-generaltor–>mybatis-generaltor:generaltor

之后双击即可,此时刷新一下项目就自动生成我们想要的,mapper和xml以及pojo

提示 BUILD SUCCESS 即生成成功!

[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< top.orginly:mall >--------------------------
[INFO] Building mall 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- mybatis-generator-maven-plugin:1.4.0:generate (default-cli) @ mall ---
[INFO] Connecting to the Database
[INFO] Introspecting table mall_user
[INFO] Introspecting table mall_category
[INFO] Introspecting table mall_goods
[INFO] Introspecting table mall_order
[INFO] Introspecting table mall_order_goods
[INFO] Introspecting table mall_cart
[INFO] Generating Primary Key class for table mall_user
[INFO] Generating Record class for table mall_user
[INFO] Generating Mapper Interface for table mall_user
[INFO] Generating SQL Map for table mall_user
[INFO] Generating Record class for table mall_category
[INFO] Generating Mapper Interface for table mall_category
[INFO] Generating SQL Map for table mall_category
[INFO] Generating Record class for table mall_goods
[INFO] Generating Mapper Interface for table mall_goods
[INFO] Generating SQL Map for table mall_goods
[INFO] Generating Primary Key class for table mall_order
[INFO] Generating Record class for table mall_order
[INFO] Generating Mapper Interface for table mall_order
[INFO] Generating SQL Map for table mall_order
[INFO] Generating Record class for table mall_order_goods
[INFO] Generating Mapper Interface for table mall_order_goods
[INFO] Generating SQL Map for table mall_order_goods
[INFO] Generating Record class for table mall_cart
[INFO] Generating Mapper Interface for table mall_cart
[INFO] Generating SQL Map for table mall_cart
[INFO] Saving file UserMapper.xml
[INFO] Saving file CategoryMapper.xml
[INFO] Saving file GoodsMapper.xml
[INFO] Saving file OrderMapper.xml
[INFO] Saving file OrderGoodsMapper.xml
[INFO] Saving file CartMapper.xml
[INFO] Saving file UserKey.java
[INFO] Saving file User.java
[INFO] Saving file UserMapper.java
[INFO] Saving file Category.java
[INFO] Saving file CategoryMapper.java
[INFO] Saving file Goods.java
[INFO] Saving file GoodsMapper.java
[INFO] Saving file OrderKey.java
[INFO] Saving file Order.java
[INFO] Saving file OrderMapper.java
[INFO] Saving file OrderGoods.java
[INFO] Saving file OrderGoodsMapper.java
[INFO] Saving file Cart.java
[INFO] Saving file CartMapper.java
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.193 s
[INFO] Finished at: 2021-06-01T22:33:37+08:00
[INFO] ------------------------------------------------------------------------

SpringBoot实现整合mybatis-generator-maven-plugin 1.4.0的更多相关文章

  1. spingBoot整合mybatis+generator+pageHelper

    spingBoot整合mybatis+generator+pageHelper 环境/版本一览: 开发工具:Intellij IDEA 2018.1.4 springboot: 2.0.4.RELEA ...

  2. idea + mybatis generator + maven 插件使用

    idea + mybatis generator + maven 插件使用 采用的是 generator 的 maven 插件的方式 ~ 1 pom.xml mybatis其它配置一样,下面是配置my ...

  3. Spring学习总结(五)——Spring整合MyBatis(Maven+MySQL)二

    接着上一篇博客<Spring整合MyBatis(Maven+MySQL)一>继续. Spring的开放性和扩张性在J2EE应用领域得到了充分的证明,与其他优秀框架无缝的集成是Spring最 ...

  4. SpringBoot之整合Mybatis(增,改,删)

    一,在上一篇文章SpringBoot之整合Mybatis中,我们使用spring boot整合了Mybatis,并演示了查询操作.接下来我们将完善这个示例,增加增,删,改的功能. 二,改动代码 1.修 ...

  5. SpringBoot系列-整合Mybatis(注解方式)

    目录 一.常用注解说明 二.实战 三.测试 四.注意事项 上一篇文章<SpringBoot系列-整合Mybatis(XML配置方式)>介绍了XML配置方式整合的过程,本文介绍下Spring ...

  6. maven 从svn导入项目遇到的问题 No marketplace entries found to handle yuicompressor maven plugin:1.3.0:compile

    版权声明:本文为博主原创文章,未经博主同意不得转载.安金龙 的博客. https://blog.csdn.net/smile0198/article/details/25463825 RT.使用ecl ...

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

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

  8. mybatis generator maven插件自动生成代码

    如果你正为无聊Dao代码的编写感到苦恼,如果你正为怕一个单词拼错导致Dao操作失败而感到苦恼,那么就可以考虑一些Mybatis generator这个差价,它会帮我们自动生成代码,类似于Hiberna ...

  9. SpringBoot之整合Mybatis范例

    依赖包: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http:/ ...

  10. SpringBoot之整合MyBatis

    今天了解一下SpringBoot如何与我们最常用的ORM框架Mybatis整合. 一. 需要在pom.xml文件里加入mybatis的依赖 <dependency> <groupId ...

随机推荐

  1. TEX Quotes UVA-272

    ​ TEX is a typesetting language developed by Donald Knuth. It takes source text together with a few ...

  2. 031- 控制语句switch

    语法 switch(表达式){ case 值1: java语句; break; case 值2: java语句; break; case 值3: java语句; break; default: jav ...

  3. hdu 4099 字典树 + 斐波那契

    题意:       给你一个串(最长40位)问你这个串是斐波那契F(n)  n <= 99999中的那个数的前缀,如果存在多个输出最小的n否则输出-1. 思路:       给的串最长40位,那 ...

  4. Android adb不是内部或外部命令 问题解决

    就是没有配置环境变量, 这个只需要将android安装:例如C:\Program File\android-sdk-windows\tools加入到系统变量Path中,需要注意的是Path中会配置的有 ...

  5. postgresql高级应用之合并单元格

    postgresql高级应用之合并单元格 转载请注明出处https://www.cnblogs.com/funnyzpc/p/14732172.html 1.写在前面✍ 继上一篇postgresql高 ...

  6. 【python】Leetcode每日一题-位1的个数

    [python]Leetcode每日一题-位1的个数 [题目描述] 编写一个函数,输入是一个无符号整数(以二进制串的形式),返回其二进制表达式中数字位数为 '1' 的个数(也被称为汉明重量). 示例1 ...

  7. 【mybatis】mybatis分页拦截器搭配bootstrap-table使用

    提前说明: 这一种方式已被我自己pass掉了,已经被新的方式迭代了.但是记录下自己曾经的成果还是有必要的,而且里面的思想还是不变的,另外技术不就是在不断地迭代中升级吗.千万不要想着一步完美,那样会让你 ...

  8. Raspberry PI 4B 安装和配置 Raspbian

    做记录,以备之后需要,待完成中 目录 做记录,以备之后需要,待完成中 下载镜像和安装程序 ssh 远程访问 下载镜像和安装程序 Raspbian: installer: ssh 远程访问 开启ssh ...

  9. 深度解析对象的hashcode和equals的差异,以及String的内存分配方式

    Q:Java对象的hashcode是怎么得到的 A:Java对象的hashcode是native方法,不是通过Java实现的.hashcode的值是根据对象的内存地址得到的一串数字. Q:如果两个对象 ...

  10. JavaScript中DOM与BOM的区别

    1.BOM BOM全称为Brower Object Model,中文翻译为浏览器对象模型,提供了独立于内容而与浏览器窗口进行交互的对象.描述了与浏览器进行交互的方法和接口.通过BOM可以用来获取或设置 ...