• mybatis逆向工程之maven使用步骤


    Maven插件生成POJO、Mapper、Sql映射文件

    1.加mbg核心包依赖:

    1 <!--mybatis逆向工程依赖-->
    2     <dependency>
    3       <groupId>org.mybatis.generator</groupId>
    4       <artifactId>mybatis-generator-core</artifactId>
    5       <version>1.3.2</version>
    6     </dependency>

    2.配置一个插件:

     1 <build>
     2     <plugins>
     3      
     4       <!--mybatis-generator插件,mbg逆向工程-->
     5       <plugin>
     6         <groupId>org.mybatis.generator</groupId>
     7         <artifactId>mybatis-generator-maven-plugin</artifactId>
     8         <version>1.3.5</version>
     9         <!--指定资源文件的路径-->
    10         <configuration>
    11           <configurationFile>srcmain
    esourcesgeneratorConfig.xml</configurationFile>
    12           <verbose>true</verbose>
    13           <overwrite>true</overwrite>
    14         </configuration>
    15         <!--此插件需要依赖的jar包资源-->
    16         <dependencies>
    17           <dependency>
    18             <groupId>mysql</groupId>
    19             <artifactId>mysql-connector-java</artifactId>
    20             <version>5.1.37</version>
    21           </dependency>
    22         </dependencies>
    23       </plugin>
    24     </plugins>
    25 
    26   <!--解决类与配置文件之间不同包报错的问题-->
    27     <resources>
    28       <resource>
    29         <directory>src/main/java</directory>
    30         <includes>
    31           <include>**/*.properties</include>
    32           <include>**/*.xml</include>
    33         </includes>
    34         <filtering>false</filtering>
    35       </resource>
    36       <resource>
    37         <directory>src/main/resources</directory>
    38         <includes>
    39           <include>**/*.properties</include>
    40           <include>**/*.xml</include>
    41         </includes>
    42         <filtering>false</filtering>
    43       </resource>
    44     </resources>
    45   </build>

    3.准备generatorConfig.xml

     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     <context id="test" targetRuntime="MyBatis3">
     7         <commentGenerator>
     8             <!-- 这个元素用来去除指定生成的注释中是否包含生成的日期 false:表示保护 -->
     9             <!-- 如果生成日期,会造成即使修改一个字段,整个实体类所有属性都会发生变化,不利于版本控制,所以设置为true -->
    10             <property name="suppressDate" value="true" />
    11             <!-- 是否去除自动生成的注释 true:是 : false:否 -->
    12             <property name="suppressAllComments" value="true" />
    13         </commentGenerator>
    14         <!--数据库链接URL,用户名、密码 -->
    15         <jdbcConnection driverClass="com.mysql.jdbc.Driver"
    16                         connectionURL="jdbc:mysql://localhost:3306/crmpro"
    17                         userId="root"
    18                         password="root">
    19         </jdbcConnection>
    20         <javaTypeResolver>
    21             <!-- This property is used to specify whether MyBatis Generator should
    22              force the use of java.math.BigDecimal for DECIMAL and NUMERIC fields, -->
    23             <property name="forceBigDecimals" value="false" />
    24         </javaTypeResolver>
    25         <!-- 指定javaBean的生成策略  文件夹自己定义-->
    26         <javaModelGenerator targetPackage="com.ljl.bean"
    27                             targetProject=".srcmainjava">
    28             <property name="enableSubPackages" value="true" />
    29             <property name="trimStrings" value="true" />
    30         </javaModelGenerator>
    31 
    32         <!-- sqlMapGenerator:sql映射生成策略: -->
    33         <sqlMapGenerator targetPackage="com.ljl.mapper"
    34                          targetProject=".srcmain
    esources">
    35             <property name="enableSubPackages" value="true" />
    36         </sqlMapGenerator>
    37 
    38         <!-- javaClientGenerator:指定mapper接口所在的位置 -->
    39         <javaClientGenerator type="XMLMAPPER" targetPackage="com.ljl.mapper"
    40                              targetProject=".srcmainjava">
    41             <property name="enableSubPackages" value="true" />
    42         </javaClientGenerator>
    43 
    44         <!-- 指定要逆向分析哪些表:根据表要创建javaBean -->
    45         <table tableName="analysis" domainObjectName="Analysis"></table>
    46         <table tableName="archives" domainObjectName="Archives"></table>
    47         <table tableName="attachment" domainObjectName="Attachment"></table>
    48         <table tableName="baoxiao" domainObjectName="BaoXiao"></table>
    49         <table tableName="customer" domainObjectName="Customer"></table>
    50         <table tableName="dept" domainObjectName="Dept"></table>
    51         <table tableName="email" domainObjectName="Email"></table>
    52         <table tableName="employee" domainObjectName="Employee"></table>
    53         <table tableName="evaluate" domainObjectName="Evaluate"></table>
    54         <table tableName="forumpost" domainObjectName="ForumPost"></table>
    55         <table tableName="function" domainObjectName="Function"></table>
    56         <table tableName="level" domainObjectName="Level"></table>
    57         <table tableName="module" domainObjectName="Module"></table>
    58         <table tableName="msg" domainObjectName="Msg"></table>
    59         <table tableName="notice" domainObjectName="Notice"></table>
    60         <table tableName="position" domainObjectName="Position"></table>
    61         <table tableName="project" domainObjectName="Project"></table>
    62         <table tableName="role" domainObjectName="Role"></table>
    63         <table tableName="sources" domainObjectName="Sources"></table>
    64         <table tableName="task" domainObjectName="Task"></table>
    65 
    66         <!--<!– 要生成哪些表 –>-->
    67         <!--<table tableName="t_user" domainObjectName="user"-->
    68         <!--enableCountByExample="false" enableUpdateByExample="false"-->
    69         <!--enableDeleteByExample="false" enableSelectByExample="false"-->
    70         <!--selectByExampleQueryId="false"></table>-->
    71     </context>
    72 </generatorConfiguration>

    4.在maven命令执行窗口执行:mybatis-generator:generate

  • 相关阅读:
    Redis 7.0 新功能新特性总览
    adb实现钉钉自动打卡 MKY
    vue2+webpack 转 vite
    zsh: command not found:nvm 的解决方案
    SSH keys 生成
    sass(dart sass)和nodesass 的区别以及 /deep/、::vdeep的支持
    nvm(node的版本管理)简介以及nvm管理node的命令介绍
    处理 code.matchAll(...) is not a function 问题
    package.json 里面的~、^
    处理 vite 里面 __require() 方法报错
  • 原文地址:https://www.cnblogs.com/ljl5921/p/12573277.html
Copyright © 2020-2023  润新知