【学习笔记】mybatis-generator使用

安装过程:

1.从plugins里搜索下载正版

2.下载文件,粘贴到使用的eclipse的相应目录中

使用:

1.在创建好的dynamic web project右键->others->Mybatis Generator Configuration File

2.编辑生成的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" >
<generatorConfiguration >
  <context id="context1" >
  <commentGenerator>
            <!-- 抑制警告 -->
            <property name="suppressTypeWarnings" value="true" />
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="false" />
            <!-- 是否生成注释代时间戳 -->
            <property name="suppressDate" value="true" />
        </commentGenerator>
    <!-- 选择数据库驱动、数据库,修改用户名和密码 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/itclass" userId="root" password="root" />
    <!-- 编辑生成的包名,例如这里的都domain是模型类 -->
    <javaModelGenerator targetPackage="eude.demo.domain" targetProject="ITClass/src" />
    <sqlMapGenerator targetPackage="eude.demo.mapper" targetProject="ITClass/src" />
    <!-- xml文件包 -->
    <javaClientGenerator targetPackage="eude.demo.dao" targetProject="ITClass/src" type="XMLMAPPER" />
    <!-- 根据数据库表的内容逐一配置,原则上每张表对应一个类,注意修改类名 -->
    <table schema="itclass" tableName="tb_user" domainObjectName="User" >
      <property name="useActualColumnNames" value="false" />
      <!-- <columnOverride column="???" property="???" /> -->
    </table>
    <table schema="itclass" tableName="tb_admin" domainObjectName="Admin" >
      <property name="useActualColumnNames" value="false" />
      <!-- <columnOverride column="???" property="???" /> -->
    </table>
    <table schema="itclass" tableName="tb_incourse" domainObjectName="InferiorClass" >
      <property name="useActualColumnNames" value="false" />
      <!-- <columnOverride column="???" property="???" /> -->
    </table>
    <table schema="itclass" tableName="tb_sucourse" domainObjectName="SuperiorClass" >
      <property name="useActualColumnNames" value="false" />
      <!-- <columnOverride column="???" property="???" /> -->
    </table>
    <table schema="itclass" tableName="tb_course" domainObjectName="Course" >
      <property name="useActualColumnNames" value="false" />
      <!-- <columnOverride column="???" property="???" /> -->
    </table>
    <table schema="itclass" tableName="tb_video" domainObjectName="Video" >
      <property name="useActualColumnNames" value="false" />
      <!-- <columnOverride column="???" property="???" /> -->
    </table>
  </context>
</generatorConfiguration>

 

仅为参考,类名和包名依据个人习惯,但是在我修改包名的时候有个别情况下会只创建代码成功,包无法生成的情况,暂时还不明白具体原因,如果大家有类似问题可以一起讨论一下

3.一键生成对应代码

右键刚刚编辑的配置文件->Generate Mybatis/iBATIS Artifacts

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值