一、 建立好数据库,数据库名为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="[email protected]"> </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>
四、 运行并生成文件:
生成的文件
MyBatis Generator使用
时间: 2024-10-09 02:18:32