springboot集成mybatis官方生成器

来自:网络
时间:2021-11-22
阅读:
目录

引入习惯plugin

<!-- mybatis generator 自动生成代码插件 -->
			<plugin>
				<groupId>org.mybatis.generator</groupId>
				<artifactId>mybatis-generator-maven-plugin</artifactId>
				<version>1.3.7</version>
				<configuration>
					<configurationFile>src/main/resources/generator/generator-config.xml</configurationFile>
					<overwrite>true</overwrite>
					<verbose>true</verbose>
				</configuration>
				<dependencies>
					<dependency>
						<groupId>mysql</groupId>
						<artifactId>mysql-connector-java</artifactId>
						<version>8.0.22</version>
					</dependency>
				</dependencies>
			</plugin>

springboot集成mybatis官方生成器

resource下插件代码生成器配置

创建generator文件夹,并创建generator-config.xml

springboot集成mybatis官方生成器

<?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="Mysql" targetRuntime="MyBatis3" defaultModelType="flat">

        <!-- 自动检查关键字,为关键字增加反引号 -->
        <property name="autoDelimitKeywords" value="true"/>
        <property name="beginningDelimiter" value="`"/>
        <property name="endingDelimiter" value="`"/>

        <!--覆盖生成 XML 文件-->
        <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />
        <!-- 生成的实体类添加 toString()方法 -->
        <plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>

        <!-- 不生成注释 -->
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                        connectionURL="jdbc:mysql://rm-bp1tja0cb2r7t5il5ko.mysql.rds.aliyuncs.com:3306/wiki_dev?serverTimezone=Asia/Shanghai"
                        userId="wiki_dev"
                        password="Wiki677877">
        </jdbcConnection>

        <!-- domain 类的位置 -->
        <javaModelGenerator targetProject="src\main\java"
                            targetPackage="cool.tsy.wiki.domain"/>

        <!-- mapper xml的位置 -->
        <sqlMapGenerator targetProject="src\main\resources"
                         targetPackage="mapper"/>

        <!-- mapper类的位置 -->
        <javaClientGenerator targetProject="src\main\java"
                             targetPackage="cool.tsy.wiki.mapper"
                             type="XMLMAPPER"/>

        <table tableName="demo" domainObjectName="Demo"/>
        <table tableName="ebook"/>
        <table tableName="category"/>
        <table tableName="doc"/>
        <table tableName="content"/>
        <table tableName="user"/>
        <table tableName="ebook_snapshot"/>
    </context>
</generatorConfiguration>

添加maven命令

点击edit config

springboot集成mybatis官方生成器

选择添加maven命令

springboot集成mybatis官方生成器

输入这样一条命令

springboot集成mybatis官方生成器

mybatis-generator:generate -e

新建一张数据库表进行测试 点击运行

如下图所示,完成代码生成

springboot集成mybatis官方生成器

到此这篇关于springboot集成mybatis官方生成器的文章就介绍到这了,更多相关springboot集成mybatis生成器内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

返回顶部
顶部