一、创建SpringBoot项目,引入相关依赖包

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>com.example</groupId>
  6. <artifactId>mall</artifactId>
  7. <version>0.0.1-SNAPSHOT</version>
  8. <packaging>jar</packaging>
  9. <name>mall</name>
  10. <description>Demo project for Spring Boot</description>
  11. <parent>
  12. <groupId>org.springframework.boot</groupId>
  13. <artifactId>spring-boot-starter-parent</artifactId>
  14. <version>2.0.5.RELEASE</version>
  15. <relativePath/> <!-- lookup parent from repository -->
  16. </parent>
  17. <properties>
  18. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  19. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  20. <java.version>1.8</java.version>
  21. <mybatis.version>1.3.2</mybatis.version>
  22. </properties>
  23. <dependencies>
  24. <dependency>
  25. <groupId>org.springframework.boot</groupId>
  26. <artifactId>spring-boot-starter-web</artifactId>
  27. </dependency>
  28. <dependency>
  29. <groupId>org.springframework.boot</groupId>
  30. <artifactId>spring-boot-starter-test</artifactId>
  31. <scope>test</scope>
  32. </dependency>
  33. <!-- spring-boot mybatis依赖 start -->
  34. <dependency>
  35. <groupId>org.mybatis.spring.boot</groupId>
  36. <artifactId>mybatis-spring-boot-starter</artifactId>
  37. <version>${mybatis.version}</version>
  38. </dependency>
  39. <!-- spring-boot mybatis依赖 end -->
  40. <!-- mysql 数据库驱动 start -->
  41. <dependency>
  42. <groupId>mysql</groupId>
  43. <artifactId>mysql-connector-java</artifactId>
  44. <scope>runtime</scope>
  45. </dependency>
  46. <!-- mysql 数据库驱动 end -->
  47. <!-- Druid数据库连接池 start -->
  48. <dependency>
  49. <groupId>com.alibaba</groupId>
  50. <artifactId>druid</artifactId>
  51. <version>1.0.31</version>
  52. </dependency>
  53. <!-- Druid数据库连接池 end -->
  54. </dependencies>
  55. <build>
  56. <plugins>
  57. <plugin>
  58. <groupId>org.springframework.boot</groupId>
  59. <artifactId>spring-boot-maven-plugin</artifactId>
  60. </plugin>
  61. <plugin>
  62. <!--Mybatis-generator插件,用于自动生成Mapper和POJO-->
  63. <groupId>org.mybatis.generator</groupId>
  64. <artifactId>mybatis-generator-maven-plugin</artifactId>
  65. <version>1.3.2</version>
  66. <configuration>
  67. <!--配置文件的位置-->
  68. <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
  69. <verbose>true</verbose>
  70. <overwrite>true</overwrite>
  71. </configuration>
  72. <executions>
  73. <execution>
  74. <id>Generate MyBatis Artifacts</id>
  75. <goals>
  76. <goal>generate</goal>
  77. </goals>
  78. </execution>
  79. </executions>
  80. <dependencies>
  81. <dependency>
  82. <groupId>mysql</groupId>
  83. <artifactId>mysql-connector-java</artifactId>
  84. <version>5.1.6</version>
  85. </dependency>
  86. <dependency>
  87. <groupId>org.mybatis.generator</groupId>
  88. <artifactId>mybatis-generator-core</artifactId>
  89. <version>1.3.2</version>
  90. </dependency>
  91. </dependencies>
  92. </plugin>
  93. </plugins>
  94. </build>
  95. </project>

二、创建generatorConfig.xml生成器配置文件和datasource.properties文件(在lib目录中放入相应的mysql连接器mysql-connector-java-5.1.6.jar)

  1. spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
  2. spring.datasource.url=jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf8&useSSL=false
  3. spring.datasource.username=root
  4. spring.datasource.password=123456
  5. spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  6. spring.datasource.driverLocation=./lib/mysql-connector-java-5.1.6-bin.jar
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE generatorConfiguration
  3. PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  4. "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
  5. <generatorConfiguration>
  6. <!--导入属性配置-->
  7. <properties resource="datasource.properties"></properties>
  8. <!--指定特定数据库的jdbc驱动jar包的位置-->
  9. <classPathEntry location="${spring.datasource.driverLocation}"/>
  10. <context id="default" targetRuntime="MyBatis3">
  11. <!-- optional,旨在创建class时,对注释进行控制 -->
  12. <commentGenerator>
  13. <property name="suppressDate" value="true"/>
  14. <property name="suppressAllComments" value="true"/>
  15. </commentGenerator>
  16. <!--jdbc的数据库连接 -->
  17. <jdbcConnection
  18. driverClass="${spring.datasource.driver-class-name}"
  19. connectionURL="${spring.datasource.url}"
  20. userId="${spring.datasource.username}"
  21. password="${spring.datasource.password}">
  22. </jdbcConnection>
  23. <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
  24. <javaTypeResolver>
  25. <property name="forceBigDecimals" value="false"/>
  26. </javaTypeResolver>
  27. <!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
  28. targetPackage 指定生成的model生成所在的包名
  29. targetProject 指定在该项目下所在的路径
  30. -->
  31. <!--<javaModelGenerator targetPackage="com.mmall.pojo" targetProject=".\src\main\java">-->
  32. <javaModelGenerator targetPackage="com.example.mall.pojo" targetProject="./src/main/java">
  33. <!-- 是否允许子包,即targetPackage.schemaName.tableName -->
  34. <property name="enableSubPackages" value="false"/>
  35. <!-- 是否对model添加 构造函数 -->
  36. <property name="constructorBased" value="true"/>
  37. <!-- 是否对类CHAR类型的列的数据进行trim操作 -->
  38. <property name="trimStrings" value="true"/>
  39. <!-- 建立的Model对象是否 不可改变 即生成的Model对象不会有 setter方法,只有构造方法 -->
  40. <property name="immutable" value="false"/>
  41. </javaModelGenerator>
  42. <!--mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
  43. <!--<sqlMapGenerator targetPackage="mappers" targetProject=".\src\main\resources">-->
  44. <sqlMapGenerator targetPackage="mappers" targetProject="./src/main/resources">
  45. <property name="enableSubPackages" value="false"/>
  46. </sqlMapGenerator>
  47. <!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
  48. type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
  49. type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
  50. type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口
  51. -->
  52. <!-- targetPackage:mapper接口dao生成的位置 -->
  53. <!--<javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" targetProject=".\src\main\java">-->
  54. <javaClientGenerator type="XMLMAPPER" targetPackage="com.example.mall.dao" targetProject="./src/main/java">
  55. <!-- enableSubPackages:是否让schema作为包的后缀 -->
  56. <property name="enableSubPackages" value="false" />
  57. </javaClientGenerator>
  58. <!-- 要生成哪些表 -->
  59. <table tableName="mmall_shipping" domainObjectName="Shipping" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  60. <table tableName="mmall_cart" domainObjectName="Cart" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  61. <table tableName="mmall_cart_item" domainObjectName="CartItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  62. <table tableName="mmall_category" domainObjectName="Category" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  63. <table tableName="mmall_order" domainObjectName="Order" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  64. <table tableName="mmall_order_item" domainObjectName="OrderItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  65. <table tableName="mmall_pay_info" domainObjectName="PayInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  66. <table tableName="mmall_product" domainObjectName="Product" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
  67. <columnOverride column="detail" jdbcType="VARCHAR" />
  68. <columnOverride column="sub_images" jdbcType="VARCHAR" />
  69. </table>
  70. <table tableName="mmall_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  71. </context>
  72. </generatorConfiguration>

三、项目目录和启动代码生成器插件

项目目录:

启动代码生成器:

详情见gitlab的mall商城项目

SpringBoot与Mybatis整合,插件生成dao、mapper、pojo的更多相关文章

  1. mybatis逆向生成dao mapper和example.java文件

    mabatis插件 <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>myba ...

  2. SpringBoot+Shiro+mybatis整合实战

    SpringBoot+Shiro+mybatis整合 1. 使用Springboot版本2.0.4 与shiro的版本 引入springboot和shiro依赖 <?xml version=&q ...

  3. 30分钟带你了解Springboot与Mybatis整合最佳实践

    前言:Springboot怎么使用想必也无需我多言,Mybitas作为实用性极强的ORM框架也深受广大开发人员喜爱,有关如何整合它们的文章在网络上随处可见.但是今天我会从实战的角度出发,谈谈我对二者结 ...

  4. SpringBoot与Mybatis整合方式01(源码分析)

    前言:入职新公司,SpringBoot和Mybatis都被封装了一次,光用而不知道原理实在受不了,于是开始恶补源码,由于刚开始比较浅,存属娱乐,大神勿喷. 就如网上的流传的SpringBoot与Myb ...

  5. 开发环境搭建之springboot+tk.mybatis整合使用逆向工程

    一,引入xml文件: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorCo ...

  6. Mybatis框架(9)---Mybatis自定义插件生成雪花ID做为表主键项目

    Mybatis自定义插件生成雪花ID做为主键项目 先附上项目项目GitHub地址 spring-boot-mybatis-interceptor 有关Mybatis雪花ID主键插件前面写了两篇博客作为 ...

  7. SpringBoot 添加mybatis generator 自动生成代码插件

    自动生成数据层代码,提高开发效率 1.pom添加插件,并指定配置文件路径 <!-- mybatis generator 自动生成代码插件 --> <plugin> <gr ...

  8. SpringBoot系列——MyBatis整合

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

  9. (五)SpringBoot2.0基础篇- Mybatis与插件生成代码

    SpringBoot与Mybatis合并 一.创建SpringBoot项目,引入相关依赖包: <?xml version="1.0" encoding="UTF-8 ...

  10. SpringBoot与Mybatis整合实例详解

    介绍 从Spring Boot项目名称中的Boot可以看出来,SpringBoot的作用在于创建和启动新的基于Spring框架的项目,它的目的是帮助开发人员很容易的创建出独立运行的产品和产品级别的基于 ...

随机推荐

  1. string常用成员函数

    string常用成员函数 std::string::clear Clear string Erases the contents of the string, which becomes an emp ...

  2. 【代码审计】seacms 前台Getshell分析

    一.漏洞分析 漏洞触发点search.php 211-213行 跟进parseIf 函数 ./include/main.class.php 这里要注意 3118行的位置,可以看到未做任何处理的eval ...

  3. spring controller中默认转发、forward转发、redirect转发之间的区别

    默认转发 @RequestMapping("/123") public String test(HttpSession session) { System.out.println( ...

  4. LoadRunner通过验证参数判断事物的成功与失败

    if(atoi(lr_eval_string("{Param_DiscountID}")) > 0){ //lr_message("多机多酒:%s",lr ...

  5. [Python] Tkinter的食用方法_01_简单界面

    #开始 放假之后感觉整个人已经放飞自我了,完全不知道自己一天天在干什么,明明有很多的事情需要做,但是实际上每天啥都没做,,,虚度光阴... 晚上突然心烦意乱,开始思考今天一天都做了什么,感觉很有负罪感 ...

  6. 树莓派安装中文输入法Fcitx及Google拼音输入法

    本来是想给树莓派安装搜狗输入法的, 搜狗输入法Linux版:https://pinyin.sogou.com/linux/?r=pinyin 但是一直安装不成功,后面发现原来是系统架构不同导致的,搜狗 ...

  7. Codeforces Round #622 (Div. 2) A. Fast Food Restaurant

    Tired of boring office work, Denis decided to open a fast food restaurant. On the first day he made ...

  8. 【C语言】找出1000以内所有的素数

    #include<stdio.h> int main() { int i, j, t; ; i <= ; i++) { ; ; j < i; j++) { ) { t = ; ...

  9. 基于SILVACO ATLAS的a-IGZO薄膜晶体管二维器件仿真(08)

    进展比较慢啊... 根据江南大学硕士论文IGZO/IZO双有源层薄膜晶体管特性的模拟研究: 其中, gCBa:类受主导带尾态 gVBd:类施主价带尾态 gGd:类施主氧空位态 NDeep:价带尾深施主 ...

  10. redis介绍、单机安装以及java调用

    什么是redis Redis是用C语言开发的一个开源的高性能键值对(key-value)数据库.和传统的关系型数据库不一样,不一定遵循传统数据库的一些基本要求(非关系型的.分布式的.开源的.水平可扩展 ...