下载mybatis generator插件
将features、plugins拷贝到myeclipse10下的dropins文件夹中,如下图所示,重启myeclipse。
以下以MySQL为例逆向生成映射文件,其中数据库为test表为userinfo,id字段自增。
创建一新的web project mybatis_generator,并添加sql驱动jar包。
在src中创建一个MyBatis生成orm文件的配置文件,单击next,保持默认设置finish即可。
对生成的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" targetRuntime="MyBatis3Simple"><!-- 配置注释 -->
<commentGenerator>
<property name="suppressAllComments" value="false"/><!-- 配置是否取消注释 -->
<property name="suppressDate" value="true" /><!-- 配置 注释是否显示日期 -->
</commentGenerator><!-- 配置jdbc连接数据库-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.4.249:3306/cloud_canteen_group" userId="root"
password="1" />
<!-- 配置生成的实体类放置 -->
<javaModelGenerator targetPackage="vo" targetProject="cloud_canteen_api_db/src/main/java" /><!-- 配置生成的实现文件XML放置 -->
<sqlMapGenerator targetPackage="mapper" targetProject="cloud_canteen_api_db/src/main/java" /><!-- 配置生成的dao接口放置 -->
<javaClientGenerator targetPackage="dao" targetProject="cloud_canteen_api_db/src/main/java" type="XMLMAPPER" /><!-- 配置要生成的实体对应的表 % 代表所有表 -->
<table schema="scott" tableName="order_payrec" enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"
>
</table><!-- 配置要生成的实体对应的类名
<table schema="scott" tableName="t_10_01_student" domainObjectName="Stduent"> </table>
-->
</context>
</generatorConfiguration>右键配置文件,选择Generator MyBatis/iBATIS Artifacts即可生成orm映射文件