Mybatis 自动生成代码插件&IDEA插件

Mybatis 自动生成代码的插件使用方法

1、下载Mybatis的jar包插件
mybatis-generator-core-1.3.2.jar

2、下载数据库驱动
本例子中采用mysql数据库
mysql-connector-java-5.1.18.jar

3、配置文件 generatorConfig.xml



<generatorConfiguration>
    
    <classPathEntry    location="mysql-connector-java-5.1.18.jar"/>
    <context id="DB2Tables"    targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <property name="suppressAllComments" value="true"/>
        commentGenerator>
        
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://ip:port/db?characterEncoding=UTF-8" userId="xxx" password="xxx">
        jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        javaTypeResolver>
        
        <javaModelGenerator targetPackage="com.jd.notice.domain.common" targetProject="src">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        javaModelGenerator>
        
        <sqlMapGenerator targetPackage="notice.mapping" targetProject="src">
            <property name="enableSubPackages" value="true"/>
        sqlMapGenerator>
        
        
        
        <table tableName="notice_message_record" domainObjectName="NoticeMessageRecord" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">table>
                <table tableName="notice_message_template" domainObjectName="NoticeMessageTemplate" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">table>
                        <table tableName="notice_business_apply" domainObjectName="NoticeBusinessApply" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">table>
    context>
generatorConfiguration>

4、执行java命令生成代码

java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite

Mybatis 自动生成代码插件&IDEA插件_第1张图片

5、插件集成到 idea中的一篇好文
http://blog.csdn.net/lovesummerforever/article/details/50266009

ps:intellij插件iBATIS/MyBatis
mini-plugin 可以让我们从dao层直接直接点击到对应的xml,很方便快捷。

你可能感兴趣的:(Mybatis)