MyBatis Generator使用

一、            建立好数据库,数据库名为db_netlog,结构如下:

技术文章

二、到网站上面下载:mybatis-generator-core-1.3.2.jar

当然运行 mybatis-generator 生成的代码还需要下载 mybatis 的 jar 包,和相关数据库的 jdbc。MyBatis中,可以使用Generator自动生成代码,包括DAO层、 MODEL层 、MAPPING SQL映射文件。

三、            配置生成文件:

技术文章
<?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="../lib/mysql-connector-java-5.1.22-bin.jar" />

   

    <context id="zcw" targetRuntime="MyBatis3">

   

        <plugin type="org.mybatis.generator.plugins.AddLimitOffsetPlugin" />

       

        <jdbcConnection driverClass="com.mysql.jdbc.Driver"

            connectionURL="jdbc:mysql://localhost:3361/db_netlog" userId="zcw" password="zcw@mysql">

        </jdbcConnection>

 

        <javaTypeResolver>

            <property name="forceBigDecimals" value="false" />

        </javaTypeResolver>

 

        <javaModelGenerator targetPackage="com.dataaccess.entity.netlog"

            targetProject="../src/">

            <property name="enableSubPackages" value="true" />

            <property name="trimStrings" value="true" />

        </javaModelGenerator>

 

        <sqlMapGenerator targetPackage="com.dataaccess.dao.netlog"

            targetProject="../src/">

            <property name="enableSubPackages" value="true" />

        </sqlMapGenerator>

 

        <javaClientGenerator type="XMLMAPPER"

            targetPackage="com.dataaccess.dao.netlog" targetProject="../src/">

            <property name="enableSubPackages" value="true" />

        </javaClientGenerator>

       

        <table schema="zcw" tableName="tb_domain_log" domainObjectName="DomainLog">

            <property name="useActualColumnNames" value="true" />

            <generatedKey column="ID" sqlStatement="mysql" identity="true" />

        </table>

       

    </context>

</generatorConfiguration>
View Code

四、 运行并生成文件:

技术文章

生成的文件

技术文章

 

MyBatis Generator使用,布布扣,bubuko.com

文章来自:http://www.cnblogs.com/super-d2/p/3869812.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3