Mybatis-Generator逆向工程

1 篇文章 0 订阅
1 篇文章 0 订阅

@Mybatis-Generator逆向工程

Mybatis-Generator逆向工程

学习总结 springboot+mybatis+generator

1.创建工程:

2.项目结构:也可以

-也可以不创建目录,会自动生成

3.pom文件添加generator依赖

<!-- mybatis generator 自动生成代码插件 -->
<plugin>
   <groupId>org.mybatis.generator</groupId>
   <artifactId>mybatis-generator-maven-plugin</artifactId>
   <version>1.3.2</version>
   <dependencies>
      <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
         <version>5.1.38</version>
      </dependency>
   </dependencies>
   <configuration>
      <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
      <overwrite>true</overwrite>
      <verbose>true</verbose>
   </configuration>
</plugin>

4.application.yml配置

server:
  port: 8080

spring:
  datasource:
    url: jdbc:mysql://127.0.0.1/test?serverTimezone=CTT&characterEncoding=utf-8
    username: root
    password: 123456
    driver-class-name: com.mysql.jdbc.Driver
  devtools:
    restart:
      enabled: true
  jackson:
      serialization:
        #格式化输出
        indent_output: true
        #忽略无法转换的对象
        fail_on_empty_beans: false
      #设置空如何序列化
      defaultPropertyInclusion: NON_EMPTY
      deserialization:
        #允许对象忽略json中不存在的属性
        fail_on_unknown_properties: false
      parser:
        #允许出现特殊字符和转义符
        allow_unquoted_control_chars: true
        #允许出现单引号
        allow_single_quotes: true
mybatis:
  mapper-locations: classpath:mapper/*.xml  #注意:一定要对应mapper映射xml文件的所在路径
  type-aliases-package: com.lucunxin.entity  # 注意:对应实体类的路径
logging:
  level:
    com.student.mapper: DEBUG
pagehelper:
  reasonable: true
  support-methods-arguments: true
  page-size-zero: true
  helperDialect: mysql

5.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="mybatisToTables" targetRuntime="MyBatis3">
        <!-- 使用自带序列化插件 -->
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>

        <!-- 自定义的注释生成插件-->
        <!-- <plugin type="com.guri.lechunxuan.plugins.CommentPlugin"> -->
        <!-- 抑制警告 -->
        <!--  <property name="suppressTypeWarnings" value="true" /> -->
        <!-- 是否去除自动生成的注释 true:是 : false:-->
        <!-- <property name="suppressAllComments" value="true" /> -->
        <!-- 是否生成注释代时间戳 -->
        <!-- <property name="suppressDate" value="false" /> -->
        <!-- </plugin> -->


        <!-- 数据库 -->
        <jdbcConnection
                driverClass="com.mysql.jdbc.Driver"
                connectionURL="jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&amp;characterEncoding=UTF8"
                userId="root" password="123456">
            <property name="useInformationSchema" value="true"/>
        </jdbcConnection>

        <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
            NUMERIC 类型解析为java.math.BigDecimal -->
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>

        <!-- 生成文件存放路径 -->
        <!-- targetProject:生成PO类的位置 -->
        <javaModelGenerator
                targetPackage="com.lucunxin.entity"
                targetProject="src/main/java">
            <!-- enableSubPackages:是否让schema作为包的后缀 -->
            <property name="enableSubPackages" value="false" />
            <!-- 从数据库返回的值被清理前后的空格 -->
            <property name="trimStrings" value="true" />
        </javaModelGenerator>


        <!-- targetProject:mapper映射文件生成的位置 -->
        <sqlMapGenerator
                targetPackage="mybatis.mapper"
                targetProject="src/main/resources">
            <!-- enableSubPackages:是否让schema作为包的后缀 -->
            <property name="enableSubPackages" value="false" />
        </sqlMapGenerator>


        <!-- targetPackage:mapper接口生成的位置 -->
        <javaClientGenerator
                targetPackage="com.lucunxin.mapper"
                targetProject="src/main/java"
                type="XMLMAPPER">
            <!-- enableSubPackages:是否让schema作为包的后缀 -->
            <property name="enableSubPackages" value="false" />
        </javaClientGenerator>
        <!-- 数据库表 -->
        <table
                tableName="student"
                domainObjectName="Student"
                enableCountByExample="false"
                enableUpdateByExample="false"
                enableDeleteByExample="false"
                enableSelectByExample="false"
                selectByExampleQueryId="false">
            <!-- <generatedKey column="id_role" sqlStatement="MySql" identity="true"/> -->
        </table>
    </context>
</generatorConfiguration>

6.在run启动添加maven启动generatorConfig

在这里插入图片描述

7.运行generator

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值