MyBatis-MyEclipse+MyBatis-Generator插件

插件准备:

链接:http://pan.baidu.com/s/1bpHwgt5 密码:u7in

数据库(mysql)表准备:

    CREATE TABLE `role` (
      `id` int(11) NOT NULL auto_increment,
      `rolename` varchar(20) default NULL,
      `note` varchar(100) default NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8

创建项目MyBatis

创建相关的包

  • com.yan.po
  • com.yan.dao
  • com.yan.mapper

创建资源包

  • src/main/resources

生成generatorConfig.xml

  • 右击项目
  • new
  • Other
  • MyBatis Generator Configuration File
  • Next
  • Location中填写存放的位置:/MyBatis/src/main/resources
  • 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 >
    <!-- 数据库驱动包位置 --> 
    <classPathEntry location="F:\Maven\repository\mysql\mysql-connector-java\5.1.38\mysql-connector-java-5.1.38.jar"/>
      <context id="context1" >
      <commentGenerator>
        <!-- 是否去除自动生成的注释 true:是 : false:否 -->  
        <property name="suppressAllComments" value="true"/>
      </commentGenerator>
      <!-- 数据库链接URL、用户名、密码 --> 
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/mysql" userId="root" password="mysql" />
        <!-- 生成模型的包名和位置 -->
        <javaModelGenerator targetPackage="com.yan.po" targetProject="MyBatis/src/main/java" />
        <!-- 生成的映射文件报名和位置 --> 
        <sqlMapGenerator targetPackage="com.yan.mapper" targetProject="MyBatis/src/main/java" />
        <!-- 生成DAO的包名和位置 --> 
        <javaClientGenerator targetPackage="com.yan.dao" targetProject="MyBatis/src/main/java" type="XMLMAPPER" />
        <!-- 要生成的那些表(更改tableName 和domainObjectName 就可以了) --> 
        <table schema="mysql" tableName="role" domainObjectName="Role" enableCountByExample="false" enableUpdateByExample="false"  
                enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
          <columnOverride column="id" property="id" />
          <columnOverride column="rolename" property="roleName" />
          <columnOverride column="note" property="note"/>
        </table>
      </context>
    </generatorConfiguration>

生成文件

右击generatorConfig.xml,选择Generator MyBatis/IBATIS Artifacts

参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值