When using MyBatis, the handwritten XML or model file is a definitely work, so you can use the Mybatis-gennerator plugin to automatically generate the DAO, Bean, and mapper XML files needed for MyBatis
(Original address: http://blog.csdn.net/tolcf/article/details/50835165)
Accessories:http://files.cnblogs.com/files/cc-robot/generator.rar
Unzip the attachment locally, I put it in the D:\web\java directory.
You only need to modify the underlined portions of the XML configuration file below.
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:\web\java\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://127.0.0.1:3306/Dbname?characterencoding=utf8"userId= "dbuser"Password= "dbpass"> - <!--<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= "com.callservice.model"Targetproject= "D:\web\java\generator\src"> - < Propertyname= "Enablesubpackages"value= "true" /> + < Propertyname= "Trimstrings"value= "true" /> A </Javamodelgenerator> at <!--generated map file package name and location - - <SqlmapgeneratorTargetpackage= "com.callservice.mapping"Targetproject= "D:\web\java\generator\src"> - < Propertyname= "Enablesubpackages"value= "true" /> - </Sqlmapgenerator> - <!--generate DAO's package name and location - - <Javaclientgeneratortype= "Xmlmapper"Targetpackage= "Com.callservice.dao"Targetproject= "D:\web\java\generator\src"> in < Propertyname= "Enablesubpackages"value= "true" /> - </Javaclientgenerator> to <!--to generate those tables (change tablename and Domainobjectname) - + <TableTableName= "admin"Domainobjectname= "admin"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false" /> - <!--<table tablename= "Course_info" domainobjectname= "Courseinfo" enablecountbyexample= "false" Enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "False"/> the <table tablename= "Course_user_info" domainobjectname= "Courseuserinfo" enablecountbyexample= "false" enableUp Datebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/ > - * </Context> $ </generatorconfiguration>
Then open command-line mode under WINDWOS, switch to generator directory, execute:
Java-jar Mybatis-generator-core-1.3.2.jar-configfile Generator.xml-overwrite
A successfully appears, proving that the build was successful.
Then switch to the GENERATOR/SRC directory, you can see the file just generated, there are three folders: Dao,mapping,model, copy the generated files to the corresponding project directory.
MyBatis automatic generation of DAO, model, mapper XML file