使用Mybatis逆向工程生成对应的实体类、DAO、映射文件

时间:2025-05-13 15:00:12
  • <?xml version="1.0" encoding="UTF-8"?>
  • <!DOCTYPE generatorConfiguration PUBLIC
  • "-////DTD MyBatis Generator Configuration 1.0//EN"
  • "/dtd/mybatis-generator-config_1_0.dtd">
  • <generatorConfiguration>
  • <context id="DB2Tables" targetRuntime="MyBatis3Simple" defaultModelType="flat">
  • <!-- 通用 Mapper 继承的接口 -->
  • <plugin type="">
  • <property name="mappers" value=""/>
  • </plugin>
  • <commentGenerator>
  • <!-- 不生成时间戳 -->
  • <property name="suppressDate" value="true"/>
  • <!-- 生成注解 -->
  • <property name="suppressAllComments" value="false"/>
  • <!-- 注解采用数据库的标注,suppressAllComments 必须设置为 false 才会生效 -->
  • <property name="addRemarkComments" value="true"/>
  • </commentGenerator>
  • <!-- 数据库连接信息 -->
  • <jdbcConnection driverClass=""
  • connectionURL="jdbc:mysql://localhost:3306/数据库名称?characterEncoding=utf8"
  • userId="数据库用户名"
  • password="数据库密码">
  • <!-- oracle 获取数据库注解的方式,想要获取数据库注解必须添加 -->
  • <!-- <property name="remarksReporting" value="true"/> -->
  • <!-- mysql 获取数据库注解的方式,想要获取数据库注解必须添加 -->
  • <property name="useInformationSchema" value="true"/>
  • <!-- 其它类型数据库暂不支持 达梦,人大金仓-->
  • </jdbcConnection>
  • <!-- 生成实体类位置 -->
  • <javaModelGenerator targetPackage="" targetProject="src/main/java">
  • <property name="enableSubPackages" value="true"/>
  • <property name="trimStrings" value="true"/>
  • </javaModelGenerator>
  • <!-- 生成的 xml 映射文件位置 -->
  • <sqlMapGenerator targetPackage="/" targetProject="src/main/resources/mapper">
  • <property name="enableSubPackages" value="true"/>
  • </sqlMapGenerator>
  • <!-- 生成 mapper 接口的位置 -->
  • <javaClientGenerator type="XMLMAPPER" targetPackage="" targetProject="src/main/java">
  • <property name="enableSubPackages" value="true"/>
  • </javaClientGenerator>
  • <!-- 数据表 和 JAVA 实体的映射,tableName 表名,domainObjectName 实体名 -->
  • <table tableName="users" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false"
  • enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
  • </table>
  • <!-- 如果想要一次性生成所有表,可以把 tableName 配置为 %,一般不推荐这么干,开发项目的时候最好是要用到哪些表,才去生成 -->
  • <!-- <table tableName="%"/> -->
  • </context>
  • </generatorConfiguration>