安装过程:
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