官网地址

程序猿升级课

热爱开源,喜欢摸索


SpringBoot自动生成Mapper映射

项目结构

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

  • 1.pom文件中添加
<build>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
                    <overwrite>true</overwrite>
                    <verbose>true</verbose>
                </configuration>
            </plugin>
        </plugins>
    </build>
  • 2.在resources中添加配置文件
resource
|____generator
| |____generatorConfig.xml
<?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" >
<!--使用方法:mvn mybatis-generator:generate-->
<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"/>
        <!--映射的mapper.xml文件-->
        <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>
posted @ 2017-08-29 19:53  chinesszz  阅读(311)  评论(0编辑  收藏  举报
ヾ(≧O≦)〃嗷~