Mybatis-generator-core automatic generation of Do, mapping, DAO Code

Source: Internet
Author: User

Using MyBatis to configure the mapping file is a bit cumbersome and error prone, and you can use the Jar tool to generate code automatically, which is efficient and convenient

One, download two jar, and place in G:\tool\maven\generator directory (own definition)

Mybatis-generator-core-1.3.2.jar

Mysql-connector-java-5.1.34.jar

Ii. Establishment of Do table

User_info table, Id,name,password

Third, configuration Generator.xml

<?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>
<!--database Driver package Location--
<classpathentry location= "G:\tool\maven\generator\mysql-connector-java-5.1.34.jar"/>

<context id= "Db2tables" targetruntime= "MyBatis3" >
<commentGenerator>
<property name= "Suppressallcomments" value= "true"/>
</commentGenerator>
<!--database link URL, user name, password--
<jdbcconnection driverclass= "Com.mysql.jdbc.Driver" connectionurl= "Jdbc:mysql://localhost:3306/testdb" userId= "Root" password= "root" >
</jdbcConnection>
<javaTypeResolver>
<property name= "Forcebigdecimals" value= "false"/>
</javaTypeResolver>
<!--generate the package name and location of the model--
<javamodelgenerator targetpackage= "Com.yuanmeng.springdemo.model" targetproject= "G:\TOOL\MAVEN\GENERATOR\SRC" >
<property name= "Enablesubpackages" value= "true"/>
<property name= "Trimstrings" value= "true"/>
</javaModelGenerator>
<!--generated map file package name and location--
<sqlmapgenerator targetpackage= "com.yuanmeng.springdemo.mapping" targetproject= "G:\TOOL\MAVEN\GENERATOR\SRC" >
<property name= "Enablesubpackages" value= "true"/>
</sqlMapGenerator>
<!--generate DAO's package name and location--
<javaclientgenerator type= "Xmlmapper" targetpackage= "Com.yuanmeng.springdemo.dao" targetproject= "G:\tool\maven \generator\src ">
<property name= "Enablesubpackages" value= "true"/>
</javaClientGenerator>
<!--to generate those tables (you can change TableName and domainobjectname)--
<table tablename= "User_info" domainobjectname= "UserInfo" enablecountbyexample= "false" enableupdatebyexample= " False "enabledeletebyexample=" false "enableselectbyexample=" false "selectbyexamplequeryid=" false "/>
</context>
</generatorConfiguration>

Iv. Enter the G:\tool\maven\generator and execute the order Java-jar mybatis-generator-core-1.3.2.jar-configfile Generator.xml–overwrite You can generate code

Mybatis-generator-core automatic generation of Do, mapping, DAO Code

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.