欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

MyBatis-Plus通过插件将数据库表生成Entiry,Mapper.xml,Mapper.class的方式

时间:2021-01-23 10:13:48|栏目:JAVA代码|点击:

创建maven项目,修改pom.xml文件,如下:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.xxxx</groupId>
    <artifactId>parent-pom</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>
  <groupId>com.xxxx</groupId>
  <artifactId>mapper-creator</artifactId>
  <version>1.0-SNAPSHOT</version>
  <properties>
    <configuration.outputDir>d:\demo-mapper-folder</configuration.outputDir>
    <dataSource.url>jdbc:mysql://192.168.18.140:8066/TESTDB?useUnicode=true&amp;characterEncoding=UTF-8</dataSource.url>
    <dataSource.username>root</dataSource.username>
    <dataSource.password>123456</dataSource.password>
    <packageInfo.parent>com.xxxx.demotwo</packageInfo.parent>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatisplus-maven-plugin</artifactId>
        <version>1.0</version>
        <configuration>
          <!-- 输出目录(默认java.io.tmpdir) -->
          <outputDir>${configuration.outputDir}</outputDir>
          <!-- 是否覆盖同名文件(默认false) -->
          <fileOverride>true</fileOverride>
          <!-- mapper.xml 中添加二级缓存配置(默认true) -->
          <enableCache>true</enableCache>
          <!-- 开发者名称 -->
          <author>ZuoQuan Tu</author>
          <!-- 是否开启 ActiveRecord 模式(默认true) -->
          <activeRecord>false</activeRecord>
          <!-- 数据源配置,( **必配** ) -->
          <dataSource>
            <driverName>com.mysql.jdbc.Driver</driverName>
            <url>${dataSource.url}</url>
            <username>${dataSource.username}</username>
            <password>${dataSource.password}</password>
          </dataSource>
          <strategy>
            <!-- 字段生成策略,四种类型,从名称就能看出来含义:
              nochange(默认),
              underline_to_camel,(下划线转驼峰)
              remove_prefix,(去除第一个下划线的前部分,后面保持不变)
              remove_prefix_and_camel(去除第一个下划线的前部分,后面转驼峰) -->
            <naming>underline_to_camel</naming>
            <!-- 表前缀 -->
            <!--<tablePrefix>bmd_</tablePrefix>-->
            <!--Entity中的ID生成策略(默认 id_worker)-->
            <idGenType>uuid</idGenType>
            <!--自定义超类-->
            <!--<superServiceClass>com.baomidou.base.BaseService</superServiceClass>-->
            <!-- 要包含的表 与exclude 二选一配置-->
            <!--<include>-->
            <!--<property>sec_user</property>-->
            <!--<property>table1</property>-->
            <!--</include>-->
            <!-- 要排除的表 -->
            <!--<exclude>-->
            <!--<property>schema_version</property>-->
            <!--</exclude>-->
          </strategy>
          <packageInfo>
            <!-- 父级包名称,如果不写,下面的service等就需要写全包名(默认com.baomidou) -->
            <parent>${packageInfo.parent}</parent>
            <!--service包名(默认service)-->
            <service>service</service>
            <!--serviceImpl包名(默认service.impl)-->
            <serviceImpl>service.impl</serviceImpl>
            <!--entity包名(默认entity)-->
            <entity>entity</entity>
            <!--mapper包名(默认mapper)-->
            <mapper>mapper</mapper>
            <!--xml包名(默认mapper.xml)-->
            <xml>mapper</xml>
          </packageInfo>
          <template>
            <!-- 定义controller模板的路径 -->
            <!--<controller>/template/controller1.java.vm</controller>-->
          </template>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</project>

项目运行步骤

A、修改pom.xml中的properties中的各各参数的值,以适应自己项目中的配置

B、在maven的setting.xml中添加:

<pluginGroups>
  <pluginGroup>com.baomidou</pluginGroup>
</pluginGroups>

C、执行以下maven命令:

mvn mp:code

执行完成之后,即可看到弹出一个文件夹,里面包含了要生成的表的Entity,mapper,mapper.xml等

总结

上一篇:SpringBoot+WebSocket搭建简单的多人聊天系统

栏    目:JAVA代码

下一篇:java实现http的Post、Get、代理访问请求

本文标题:MyBatis-Plus通过插件将数据库表生成Entiry,Mapper.xml,Mapper.class的方式

本文地址:http://www.codeinn.net/misctech/49642.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有