MyBatis Generator 自动生成代码

18 篇文章 0 订阅
5 篇文章 0 订阅

利用MyBatis Generator 可快速高效生成,Dao,mapper.xml ,实体类以及实体类对应的Example 实类。

关于 MyBatis Generator 来快速实现代码生成,可利用Eclipse装插件,插件下载地址(http://download.csdn.net/download/sinat_27406925/9996352),把里面的文件的jar包复制到eclipse对应的jar包里面,然后重启eclipse,然后按住项目右键 new—>other 找Mybatis 即可,再就是配置generator.xml。

还是来看看怎么配置 generator.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>  
    <!-- 数据库驱动包位置 -->  
    <!--  D:\maven\repository\mysql\mysql-connector-java\5.1.32\mysql-connector-java-5.1.32.jar-->
    <classPathEntry  
        location="D:\maven\repository\mysql\mysql-connector-java\5.1.32\mysql-connector-java-5.1.32.jar" />  
    <context id="context1">  
        <commentGenerator>  
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->  
            <property name="suppressAllComments" value="true"/>  
        </commentGenerator>  
        <!-- 数据库链接URL、用户名、密码 -->  
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"  
            connectionURL="jdbc:mysql://数据库地址(自己改):3307/数据库名(自己改)" userId="用户名(自己改)" password="密码(自己改)" />  
        <!-- 生成模型的包名和位置 -->  
        <javaModelGenerator targetPackage="com.epipe.user.dal.db.po" targetProject="user-impl/src/main/java" />  
        <!-- 生成的映射文件报名和位置 -->  
        <sqlMapGenerator targetPackage="com.mapping" targetProject="user-impl/src/main/resources" />  
        <!-- 生成DAO的包名和位置 -->  
        <javaClientGenerator targetPackage="com.epipe.user.dal.db.mapper" targetProject="user-impl/src/main/java" type="XMLMAPPER" />  
        <!-- 要生成的那些表(更改tableName 和domainObjectName 就可以了) -->  
        <!--
        <table schema="ssm1" tableName="FILMINFO" domainObjectName="FilmInfo" enableCountByExample="false" enableUpdateByExample="false"  
            enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">  
            <columnOverride column="FILMID" property="FILMID" />  
            <columnOverride column="FILMNAME" property="FILMNAME" />  
            <columnOverride column="TYPEID" property="TYPEID" />  
            <columnOverride column="ACTOR" property="ACTOR" />  
            <columnOverride column="DIRECTOR" property="DIRECTOR" />  
            <columnOverride column="TICKETPRICE" property="TICKETPRICE" />  
        </table>  
        -->
        <!-- 
            domainObjectName="myuser" enableCountByExample="true" enableUpdateByExample="true"  
            enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"
            当这些为true时 生成对应的实体类的Example类,如果不想要这些Example类,可以将true 改为false即可
        --->
        <table tableName="sys_user" domainObjectName="myuser" enableCountByExample="true" enableUpdateByExample="true"  
            enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">  
            <columnOverride column="TYPEID" property="TYPEID" />  
            <columnOverride column="TYPENAME" property="TYPENAME" />  
        </table>  
    </context>  
</generatorConfiguration>  

这里写图片描述

这里写图片描述

这里写图片描述

这就是运行后生成的代码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值