mybatis-generatorConfiguration自动生成映射文件

在pom文件中添加generator插件和代码生成的配置文件

<plugin>
   <groupId>org.mybatis.generator</groupId>
   <artifactId>mybatis-generator-maven-plugin</artifactId>
   <version>1.3.5</version>
   <configuration>
      <!-- 加载mybatis用于生成代码的配置文件,这个文件要在这个路径下 -->
      <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
      <verbose>true</verbose>
      <overwrite>true</overwrite>
   </configuration>
</plugin>

generatorConfig.xm:如下
在这里插入图片描述
generatorConfig自动生成配置文件,按照注释修改成自己本地的参数即可

<?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">
<generatorConfiguration>
    <properties resource="application.properties"></properties>
    <!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包的地址      要改-->
    <classPathEntry  location="D:\Mysql\mysql-connector-java-5.0.8-bin.jar"/>
    <context id="DB2Tables"  targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!--数据库链接URL,用户名、密码       要改-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="${spring.datasource.url}" userId="${spring.datasource.username}" password="${spring.datasource.password}">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!-- 生成实体类的包名和位置          要改-->
        <javaModelGenerator targetPackage="com.ahav.meeting_details.pojo" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!-- 生成sql映射文件的包名和位置      要改-->
        <sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!-- 生成mapper接口的包名和位置         要改-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.ahav.meeting_details.mapper" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名    要改-->
        <table tableName="equipment_tab" domainObjectName="EquipmentTab" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="meeting_details_tab" domainObjectName="MeetingDetailsTab" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="meetingroom_tab" domainObjectName="MeetingroomTab" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
    </context>
</generatorConfiguration>

配置文件的修改

#指定xml映射路径,classpath代表在resources包下
mybatis.mapper-locations=classpath:mapping/*.xml
#给这个包下的类起别名
mybatis.type-aliases-package=com.ahav.reserve.pojo,com.ahav.system.entity,com.ahav.email.pojo

运行generator根据数据库表自动加载,实体类,mapper接口,mapper.xml文件,步骤如下
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
命令:mybatis-generator:generate -e

运行插件!
在这里插入图片描述
此时mapper接口,pojo,mapper映射文件已经生成!
在这里插入图片描述
对mapper接口添加该注解,@Mapper表示这个接口由mybatis实现,@Repositort表示将这个mapper交给spring管理。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值