1, download Mybatis-generator-core-1.3.2.jar, Baidu can;
2. Create a new Generator.xml file and paste the following code:
<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis Generator Configuration 1.0//en" "Http://myb Atis.org/dtd/mybatis-generator-config_1_0.dtd "><generatorconfiguration> <!--Database driver Package location - <Classpathentry Location= "G:\lijun\mybatis-generator\ojdbc14.jar"/> <ContextID= "Db2tables"Targetruntime= "MyBatis3"> <Commentgenerator> < Propertyname= "Suppressallcomments"value= "true"/> </Commentgenerator> <!--database link URL, user name, password - <jdbcconnectionDriverclass= "Oracle.jdbc.OracleDriver"Connectionurl= "JDBC:ORACLE:THIN:@112.74.80.47:1521:ORCL"userId= "Dbuser1"Password= "Dbuser1"> </jdbcconnection> <Javatyperesolver> < Propertyname= "Forcebigdecimals"value= "false"/> </Javatyperesolver> <!--Build the package name and location of the model - <JavamodelgeneratorTargetpackage= "Com.idea.pojo"Targetproject= "D:\Workspaces\MyEclipse 10\newproj\src"> < Propertyname= "Enablesubpackages"value= "true"/> < Propertyname= "Trimstrings"value= "true"/> </Javamodelgenerator> <!--generated map file package name and location - <SqlmapgeneratorTargetpackage= "Com.idea.mapping"Targetproject= "D:\Workspaces\MyEclipse 10\newproj\src"> < Propertyname= "Enablesubpackages"value= "true"/> </Sqlmapgenerator> <!--generate DAO's package name and location - <Javaclientgeneratortype= "Xmlmapper"Targetpackage= "Com.idea.dao"Targetproject= "D:\Workspaces\MyEclipse 10\newproj\src"> < Propertyname= "Enablesubpackages"value= "true"/> </Javaclientgenerator> <!--to generate those tables (change tablename and Domainobjectname) - <TableTableName= "Tbl_user"Domainobjectname= "User"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"/> </Context></generatorconfiguration>
View Code
3, execute cmd, as follows:
Java-jar G:\lijun\mybatis-generator\mybatis-generator-core-1.3.2.jar-configfile G:\lijun\mybatis-generator\ Generator.xml-overwrite
Execution Result:
MyBatis Generator finished successfully.
See the corresponding directory under the Dao,pojo,mapper have been generated, according to their actual situation to modify the code.
Mybatis-generator automatically generate Dao,pojo,mapper files