在IntelliJ IDEA中的SSM框架配置Mybatis的生成器(generator)包括插件以及generatorConfig.xml

1、添加Maven的mybatis-generator的依赖

<build>
    <plugins>
        <plugin>
        		
                <groupId>org.mybatis.generatorgroupId>
                <artifactId>mybatis-generator-maven-pluginartifactId>
                <version>1.4.0version>
			
            <dependencies>
                <dependency>
                    <groupId>mysqlgroupId>
                    <artifactId>mysql-connector-javaartifactId>
                    <version>8.0.15version>
                dependency>
            dependencies>

            <configuration>
                <overwrite>trueoverwrite>
            configuration>
        plugin>
    plugins>
build>

2、在resources目录下创建并配置generatorConfig.xml文件



<generatorConfiguration>
    
    <context id="mybatisGenerator" targetRuntime="Mybatis3">
    	
        <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />
        
        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        commentGenerator>



        
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                        connectionURL="jdbc:mysql://127.0.0.1:3306/mybatisTest?serverTimezone=UTC"
                        userId="root"
                        password="qisini"/>

        
        <javaModelGenerator targetPackage="com.di.domain" targetProject="src/main/java">
            <property name="enableSubPackages" value="true" />
            
            <property name="trimStrings" value="true" />
        javaModelGenerator>

        
        <sqlMapGenerator targetPackage="mappers" targetProject="src/main/resources">
            <property name="enableSubPackages" value="true"/>
        sqlMapGenerator>

        
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.di.dao" targetProject="src/main/java">
            <property name="enableSubPackages" value="true" />
        javaClientGenerator>


        
        <table tableName="book" domainObjectName="Book"/>
    context>
generatorConfiguration>

三个必须配置项:

  1. jdbcConnection
  2. javaModelGenerator
  3. table

必须声明的插件

<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />

上述配置文件生成的代码对应如下:
在IntelliJ IDEA中的SSM框架配置Mybatis的生成器(generator)包括插件以及generatorConfig.xml_第1张图片

3、运行插件,生成代码

在IntelliJ IDEA中的SSM框架配置Mybatis的生成器(generator)包括插件以及generatorConfig.xml_第2张图片

你可能感兴趣的:(SpringBoot)