Use Mybatis-generator to help us automatically generate mapper.xml files, DAO files, model files.
1. Required Documents
About Mybatis-generator download can go to this address: https://github.com/mybatis/generator/releases
The following documents are relevant:
From the above can be seen to have a generator.xml file, mainly is to modify the configuration information in this file.
Mybaits-generator-core-1032.jar is the core package for the mybaits generator.
Mysql-connector-java-5.1.34.jar is the jar package that connects MySQL, Ojdbc6.jar is the jar package that connects Oracle, and chooses different jar packages as needed.
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 driver package location--><classpathentry location= "E:\web\java_mybits\generator\ Ojdbc6.jar "/> <!--this time my database is Oracle, so select this jar package--
<!--<classpathentry location= "C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.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://Localhots: 3306/my_db?characterencoding=utf8 "userid="Root"Password="123456">--> <jdbcconnection driverclass=" Oracle.jdbc.driver.OracleDriver "connectionurl=" jdbc:oracle:thin:@11.10.97.14: 1521:testoms"Userid="Kfomswas"Password="Kfomswas"></jdbcconnection><javatyperesolver><property name=" Forcebigdecimals "value=" false "/></ javatyperesolver><!--generate the package name and location of the model--><javamodelgenerator targetpackage= "Dh.model" targetproject= "E:\web\java_mybits\generator\src"><property name=" Enablesubpackages "value=" true "/><property name=" Trimstrings "value=" true "/></ javamodelgenerator><!--generated map file package name and location--><sqlmapgenerator targetpackage= "dh.mapping" targetProject= "E:\web\java_mybits\generator\src"><property name=" Enablesubpackages "value=" true "/></sqlmapgenerator><!--generate DAO's package name and location-->< Javaclientgenerator type= "Xmlmapper" targetpackage= "Dh.dao" targetproject= "E:\web\java_mybits\generator\src"><property name=" Enablesubpackages "value=" true "/></javaclientgenerator><!--to generate those tables ( Change TableName and Domainobjectname will be OK)--><table tablename= "Dh_design_task"Domainobjectname="Dhdesigntask"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"/><table Tablename= "Course_user_info" domainobjectname= "Courseuserinfo" enablecountbyexample= "false" EnableUpdateByExample = "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/>
-</context></generatorConfiguration>
As shown in the code above:
Modify the Underline section to generate the appropriate file. Multi-table One-time generation files are only required to be released in the comments in the Red callout section above, and the corresponding table names can be modified.
2. Generate statements
Java-jar Mybatis-generator-core-1.3.2.jar-configfile Generator.xml-overwrite
3. Build Steps
Enter CMD in the Path box under the directory, and press ENTER to enter the build statement
Then return to show:MyBatis Generator finished successfully
The corresponding file is generated in this directory
The corresponding file has been uploaded to the file vault.
MyBatis automatically generate Mapper,dao mapping files