SpringBoot自动生成Mapper映射

项目结构

项目中如果使用关系型数据库,配合ibatis使用,只需要建立数据库表就ok,其他的就交给插件去做了。

  • 1.pom文件中添加
<build>
            <plugin>
                <groupId>org.mybatis.generatorgroupId>
                <artifactId>mybatis-generator-maven-pluginartifactId>
                <version>1.3.2version>
                <configuration>
                    <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xmlconfigurationFile>
                    <overwrite>trueoverwrite>
                    <verbose>trueverbose>
                configuration>
            plugin>
        plugins>
    build>
  • 2.在resources中添加配置文件
resource
|____generator
| |____generatorConfig.xml



<generatorConfiguration>

    <properties resource="application-test.properties"/>
    
    <classPathEntry  location="/Users/liuxin/Desktop/postgresql-42.0.0.jre6 2.jar"/>
    <context id="context1" targetRuntime="MyBatis3Simple" defaultModelType="flat">
        <property name="beginningDelimiter" value="`"/>
        <property name="endingDelimiter" value="`"/>

        <jdbcConnection driverClass="org.postgresql.Driver"
                        connectionURL="${druid.url}"
                        userId="${druid.username}"
                        password="${druid.password}">
        jdbcConnection>
        
        <javaModelGenerator targetPackage="pterosaur.account.domain" targetProject="src/main/java"/>
        
        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"/>
        
        <javaClientGenerator targetPackage="pterosaur.account.mapper" targetProject="src/main/java"

                             type="XMLMAPPER"/>
        
        <table tableName="boluome_flow" >table>
        <table tableName="boluome_refund_flow">table>
        <table tableName="boluome_refund_seettlement">table>
        <table tableName="boluome_settlement">table>
        <table tableName="boss_settlement_account">table>
        <table tableName="boss_transaction_flow">table>
        <table tableName="settlement_account">table>
        <table tableName="user_settlement_account">table>
        <table tableName="user_transcation_flow">table>

    context>
generatorConfiguration>

你可能感兴趣的:(SpringBoot)