mybatis配置 自动生成实体类

mybatis配置 自动生成实体类

  1. 直接在resources目录下面创建这个xml文件mygeneratorConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- <classPathEntry location="/Users/lihaiyan/jobsofeware/repository/mysql/mysql-connector-java/5.1.27/mysql-connector-java-5.1.27.jar" />-->
 <classPathEntry location="/Users/guantao/.m2/repository/mysql/mysql-connector-java/8.0.27/mysql-connector-java-8.0.27.jar" />


<context id="DB2Tables" targetRuntime="MyBatis3">
    <commentGenerator>
        <property name="suppressDate" value="true" />
        <!-- 是否去除自动生成的注释 true:是 ; false:否 -->
        <property name="suppressAllComments" value="false" />
        <property name="javaFileEncoding" value="UTF-8"/>
    </commentGenerator>
    <!--数据库链接地址账号密码 connectionURL="" password=""> -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                    connectionURL="jdbc:mysql://">
    </jdbcConnection>
    <javaTypeResolver>
        <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>
    <!--生成Model类存放位置 -->
    <javaModelGenerator targetPackage="com.ziroom.bsrd.noah.domain.entity.datahelper" targetProject="src/main/java">
        <property name="enableSubPackages" value="true" />
        <property name="trimStrings" value="true" />
    </javaModelGenerator>
    <!--生成映射文件存放位置 -->
    <sqlMapGenerator targetPackage="/"
                     targetProject="src/main/resources/mapping">
        <property name="enableSubPackages" value="true" />
    </sqlMapGenerator>
    <!--生成Dao类存放位置 -->
    <javaClientGenerator type="XMLMAPPER"
                         targetPackage="com.ziroom.bsrd.noah.dao.mapper" targetProject="src/main/java">
        <property name="enableSubPackages" value="true" />
    </javaClientGenerator>
    <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
    <!--<table tableName="base_regional" domainObjectName="baseRegional"
           enableCountByExample="false" enableUpdateByExample="false"
           enableDeleteByExample="false" enableSelectByExample="false"
           selectByExampleQueryId="false"/>
    <table tableName="base_regional_l2" domainObjectName="baseRegionalL2"
           enableCountByExample="false" enableUpdateByExample="false"
           enableDeleteByExample="false" enableSelectByExample="false"
           selectByExampleQueryId="false"/>-->

    <table tableName="sync_property_temp" domainObjectName="SyncPropertyTemp"
           enableCountByExample="false" enableUpdateByExample="false"
           enableDeleteByExample="false" enableSelectByExample="false"
           selectByExampleQueryId="false"/>
    <!--<table tableName="ent_enterprise" domainObjectName="EntEnterprise"
           enableCountByExample="false" enableUpdateByExample="false"
           enableDeleteByExample="false" enableSelectByExample="false"
           selectByExampleQueryId="false"/>
    <table tableName="ent_enterprise_office" domainObjectName="EntEnterpriseOffice"
           enableCountByExample="false" enableUpdateByExample="false"
           enableDeleteByExample="false" enableSelectByExample="false"
           selectByExampleQueryId="false"/>
    <table tableName="ent_office_building" domainObjectName="EntOfficeBuilding"
           enableCountByExample="false" enableUpdateByExample="false"
           enableDeleteByExample="false" enableSelectByExample="false"
           selectByExampleQueryId="false"/>
    <table tableName="ent_office_property" domainObjectName="EntOfficeProperty"
           enableCountByExample="false" enableUpdateByExample="false"
           enableDeleteByExample="false" enableSelectByExample="false"
           selectByExampleQueryId="false"/>
    <table tableName="ent_group" domainObjectName="EntGroup"
           enableCountByExample="false" enableUpdateByExample="false"
           enableDeleteByExample="false" enableSelectByExample="false"
           selectByExampleQueryId="false"/>
    <table tableName="ent_re_enterprise_group" domainObjectName="EntReEnterpriseGroup"
           enableCountByExample="false" enableUpdateByExample="false"
           enableDeleteByExample="false" enableSelectByExample="false"
           selectByExampleQueryId="false"/>-->
</context>
  1. 去idea右边找到maven projects ,然后找到你项目的pom文件,点击plugins下面有一个mybatis-generator 双击运行就行
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!对于自动生成实体类和mapper的问题,可以考虑使用MyBatis Generator插件来实现。MyBatis Generator是一个官方支持的代码生成工具,可以根据数据库表结构自动生成实体类和mapper接口。 以下是一些简单的步骤来使用MyBatis Generator插件来生成实体类和mapper: 1. 首先,您需要在您的项目中引入MyBatis Generator插件的依赖。您可以在pom.xml文件(如果您使用Maven)或build.gradle文件(如果您使用Gradle)中添加相应的依赖。 2. 接下来,编写一个MyBatis Generator的配置文件(一般命名为generatorConfig.xml),用于定义生成实体类和mapper的规则。配置文件中包含了数据库连接信息、要生成的表、生成的目标包等信息。 3. 在配置文件中,您可以配置生成的实体类的规则,例如是否使用Lombok注解、是否生成对应字段的getters和setters等。 4. 配置好generatorConfig.xml文件后,您可以执行MyBatis Generator插件来生成实体类和mapper。一般情况下,可以通过命令行或者IDE中的插件来执行。 5. 执行成功后,您将在指定的目标包中看到生成的实体类和mapper接口。这些文件将根据您在配置文件中定义的规则生成。 需要注意的是,使用MyBatis Generator插件生成的实体类和mapper只是初始化的代码,您仍然需要根据需要进行调整和扩展。 希望以上信息对您有所帮助!如有更多问题,请继续提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值