1. Create a database named db_netlog with the following structure:
2, download to the site: mybatis-generator-core-1.3.2.jar
Of course, to run the code generated by mybatis-generator, you also need to download the jar package of mybatis and the JDBC of the relevant database. In mybatis, you can use generator to automatically generate code, including Dao layer, model layer, and mapping SQL ing file.
3. configuration file generation:
<?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>
View code
4. Run and generate a file:
Generated file