首页 > 编程 > Java > 正文

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

2019-11-26 09:16:24
字体:
来源:转载
供稿:网友

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

总结

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表