当前位置: 移动技术网 > IT编程>开发语言>Java > MyBatis-Plus通过插件将数据库表生成Entiry,Mapper.xml,Mapper.class的方式

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

2019年07月19日  | 移动技术网IT编程  | 我要评论

创建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&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等

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对移动技术网的支持。如果你想了解更多相关内容请查看下面相关链接

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网