Use mybatis Generator

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.