using MyBatis To configure mapping file comparisons is cumbersome, but there are auto-generated jar tools that facilitate faster development, mainly the use of the tool and the associated configuration.
1. Download Related Resources
We need to download Mybatis-generator-core-1.3.2.jar,mysql-connector-java-5.1.34.jar (driver package corresponding to the relevant database), Generator.xml (config file)
My network disk all Related: HTTP://PAN.BAIDU.COM/S/1NTN48PB
After the download decompression will have generator.xml and two jar one is the database driver package, this depends on your own use what database can be changed, one is Mybatis-generator-core generator core package, there is a command text to generate model.
2. Configuring the Generator.xml File
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <!DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis Generator Configuration 1.0//en" "/http Mybatis.org/dtd/mybatis-generator-config_1_0.dtd ">3 <generatorconfiguration>4 <!--Database driver Package location -5 <Classpathentry Location= "D:\generator\mysql-connector-java-5.1.34.jar" /> 6 <!--<classpathentry location= "C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar"/> -7 <ContextID= "Db2tables"Targetruntime= "MyBatis3">8 <Commentgenerator>9 < Propertyname= "Suppressallcomments"value= "true" />Ten </Commentgenerator> One <!--database link URL, user name, password - A <jdbcconnectionDriverclass= "Com.mysql.jdbc.Driver"Connectionurl= "Jdbc:mysql://localhost:3306/shop"userId= "root"Password= "12345"> - <!--<jdbcconnection driverclass= "Oracle.jdbc.driver.OracleDriver" connectionurl= "Jdbc:oracle:thin: @localhost : 1521:orcl "userid=" MSA "password=" MSA > - - </jdbcconnection> the <Javatyperesolver> - < Propertyname= "Forcebigdecimals"value= "false" /> - </Javatyperesolver> - <!--Build the package name and location of the model - + <JavamodelgeneratorTargetpackage= "Andy.model"Targetproject= "D:\generator\src"> - < Propertyname= "Enablesubpackages"value= "true" /> + < Propertyname= "Trimstrings"value= "true" /> A </Javamodelgenerator> at <!--generated map file package name and location - - <SqlmapgeneratorTargetpackage= "Andy.mapping"Targetproject= "D:\generator\src"> - < Propertyname= "Enablesubpackages"value= "true" /> - </Sqlmapgenerator> - <!--generate DAO's package name and location - - <Javaclientgeneratortype= "Xmlmapper"Targetpackage= "Andy.dao"Targetproject= "D:\generator\src"> in < Propertyname= "Enablesubpackages"value= "true" /> - </Javaclientgenerator> to <!--to generate those tables (change tablename and Domainobjectname) - + <TableTableName= "User_info"Domainobjectname= "UserInfo"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false" /> - <TableTableName= "Course_info"Domainobjectname= "Courseinfo"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false" /> the <TableTableName= "Course_user_info"Domainobjectname= "Courseuserinfo"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false" /> * </Context> $ </generatorconfiguration>
Attention:
You need to modify the drive file location of the corresponding database with the database name password.
Sets the table name of the corresponding build table and the corresponding class name so that the model,dao,mappding configuration file is generated automatically.
3. Generate Configuration file
Open cmd, go to directory generator, execute command
Java-jar Mybatis-generator-core-1.3.2.jar-configfile Generator.xml-overwrite
After execution, the contents of the Dao,mapping,model file are automatically generated.
This blog is reproduced from: http://blog.csdn.net/fengshizty/article/details/43086833
Only for learning notes to use, good memory than bad pen.
MyBatis automatically generate mapping profile information using generator