MyBatis automatic generation of entity classes, DAO interfaces, and Mapping mapping files

Source: Internet
Author: User

Since MyBatis is a semi-automatic ORM framework, its work is mainly to configure the mapping mapping file, in order to reduce manual mapping file, you can use the MyBatis generator, automatically generate entity class, DAO interface and its mapping file, And then copy directly to the project to make a slight modification can be used directly.

The generator directory is as follows:

First go to the Lib folder, the directory is as follows:

(pictured on file: http://download.csdn.net/detail/qiwei31229/9790909)

Main changes Generatorconfig.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-driven<classpathentry location= "Mysql-connector-java-5.1.25-bin.jar"/> <context id= "DB2Tables" TargetRuntime= "M YBatis3 "> <commentGenerator> <property name=" Suppressdate "value=" true "/><!--whether to remove automatically generated comments true: Yes: false: No --<property name= "Suppressallcomments" value= "true"/> </commentGenerator> <!--database link URL, user name, Password--<jdbcconnection driverclass= "Com.mysql.jdbc.Driver" connectionurl= "Jdbc:mysql://127.0.0.1/test" userId  = "root" password= "123456" > </jdbcConnection> <javaTypeResolver> <property Name= "Forcebigdecimals" value= "false"/> </javaTypeResolver><!--generate the package name and location of the model--<javamodelgenerator targetpackage= "Com.shaw.cn.domain" targetproject= "src" > <property name= "Enablesu Bpackages "value=" true "/> <property name=" trimstrings "value=" true "/> </javamodelgenerat Or><!--generate the package name and location of the mapping file--<sqlmapgenerator targetpackage= "com.shaw.cn.mapping" targetproject= "src" > <property name= "enablesubp Ackages "value=" true "/> </sqlMapGenerator><!--Generate DAO's package name and location--<javaclientgenerator type= "Xmlmapper" targetpackage= "Com.shaw.cn.IDao" targetproject= "src" > <propert Y name= "enablesubpackages" value= "true"/> </javaClientGenerator><!--the table TableName to be generated is the table name or view name in the database Domainobjectname is the entity class name--<table tablename= "user_t" domainobjectname= "user" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" Selectbyexamplequeryid= "false" ></table> < /context> </generatorConfiguration>

Note that the table needs to be created in a specific database now, and then shift+ the right mouse button in the Lib folder to open the console command input:

Java-jar Mybatis-generator-core-1.3.2.jar-configfile Generatorconfig.xml-overwrite

This allows you to see the code for the developed directory in SRC.

MyBatis automatic generation of entity classes, DAO interfaces, and Mapping mapping files

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.