First, create a MAVEN project with Eclipse.
Second, under the Pom.xml file, add the following plug-in configuration:
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <modelversion>4.0.0</ Modelversion> <groupId>com.liyi.test</groupId> <artifactId>hello-mybatis</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>hello-mybatis Maven webapp</name> <url>http://maven.apache.org</url><dependencies> <dependency> <groupId>junit</groupId> <artifactid>junit</arti factid> <version>3.8.1</version> <scope>test</scope> </dependency> </DEP endencies> <build> <finalName>hello-mybatis</finalName> <pluginManagement> & Lt;plugins> <plugin> <groupId>org.mybatis.generator</groupId> < Artifactid>mybatis-generator-maven-plugin</artifactid> <version>1.3.2</version> <configuration> <configurationFile>src/main/resources/generator.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <executions> <execution> <id>generate MyBatis artifacts</id> <goals> < ;goal>generate</goal> </goals> </execution> </execut Ions> <dependencies> <dependency> <groupid>org.mybatis. Generator</groupid> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> </dependency> </dependencies> < ;/plugin> </plugins> </pluginManagement> </build></project>
Third, find the configurationfile tag from Pom.xml, and follow the path on the label (Src/main/resources/generator.xml) into the core configuration file of the following generated code, Generator.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-<c Lasspathentry location= "D:\Program files\jeesite-master\doc\maven\repository\mysql\mysql-connector-java\5.1.37\ Mysql-connector-java-5.1.37.jar "/> <!--<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 chain Access URL, username, password--<jdbcconnection driverclass= "Com.mysql.jdbc.Driver" connectionurl= "jdbc:mysql://192.168.254 .78:3306/cjb_ecommerce "userid=" root "password=" 123 "> <!--<jdbcconnection driverclass=" oracle.jdbc.drive R.Oracledriver "Connectionurl=" Jdbc:oracle:thin: @localhost: 1521:orcl "userid=" MSA "password=" MSA >--> </jdb cconnection> <javaTypeResolver> <property name= "Forcebigdecimals" value= "false"/> </javaTypeResolver> <!--generate the package name and location of the entity class, where you configure the generated entity class to be placed under the Cn.chejinbao.ecommerce.entity package--&L T;javamodelgenerator targetpackage= "cn.chejinbao.ecommerce.entity" targetproject= "D:\Program files\ Eclipseworkspace\cn-chejinbao-ecommerce\src\main\java\ "> <property name= "Enablesubpackages" value= "true"/> <property name= "tri Mstrings "value=" true "/> </javaModelGenerator> <!--generated SQL Map file package name and location, here configuration will generate SQL mapping file placed in Cn.cheji Nbao.ecommerce.mapping This package--<sqlmapgenerator targetpackage= "cn.chejinbao.ecommerce.mapping" Targetproject = "D:\Program Files\eclipseworkspace\cn-chejinbaO-ecommerce\src\main\java\ "> <property name=" enablesubpackages "value=" true "/> </sqlmapge Nerator> <!--generates the DAO's package name and location, where the generated DAO class is configured to be placed under Cn.chejinbao.ecommerce.dao this package--<javaclientgenerato R type= "Xmlmapper" targetpackage= "Cn.chejinbao.ecommerce.dao" targetproject= "D:\Program files\eclipseworkspace\ Cn-chejinbao-ecommerce\src\main\java\ "> <property name=" enablesubpackages "value=" true "/> &L T;/javaclientgenerator> <!--to generate those tables (you can change TableName and domainobjectname)-<table tablename= "CJB _admin_role "Domainobjectname=" Adminrole "enablecountbyexample=" false "enableupdatebyexample=" false " Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tableNa Me= "Cjb_administrator" domainobjectname= "Administrator" enablecountbyexample= "false" enableupdatebyexample= "false "Enabledeletebyexample=" false "enableselectbyexample=" false "selEctbyexamplequeryid= "false"/> <table tablename= "cjb_advertising" domainobjectname= "advertising" EnableCount Byexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" Selectbyexamplequeryid= "false"/> <table tablename= "Cjb_adverts" domainobjectname= "adverts" EnableCountByExa Mple= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" Selectbyexamplequeryid= "false"/> <table tablename= "cjb_announcements" domainobjectname= "Announcements" Enab Lecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false "Selectbyexamplequeryid=" false "/> <table tablename=" cjb_appointment "domainobjectname=" Appointment "Enable Countbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" Selectbyexamplequeryid= "false"/> <table tablename= "Cjb_brand"Domainobjectname=" Brand "enablecountbyexample=" false "enableupdatebyexample=" false "enabledeletebyexample=" false "Enableselectbyexample=" false "selectbyexamplequeryid=" false "/> <table tablename=" Cjb_cars "DomainObjectNa Me= "Cars" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" Enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "Cjb_cars_base" DomainObjec Tname= "Carsbase" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" Enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "Cjb_cars_body" DomainObjec Tname= "Carsbody" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" Enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "Cjb_cars_chair" DomainObje Ctname= "Carschair" enablecountbyexample= "false" enableupdatebyexample= "false" EnabledelEtebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "Cjb_c Ars_chassis "Domainobjectname=" Carschassis "enablecountbyexample=" false "enableupdatebyexample=" false " Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tableNa Me= "Cjb_cars_control" domainobjectname= "Carscontrol" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tableNa Me= "Cjb_cars_engine" domainobjectname= "Carsengine" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tableNa Me= "cjb_cars_external" domainobjectname= "Carsexternal" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" SelectbyexampLequeryid= "false"/> <table tablename= "Cjb_cars_glass" domainobjectname= "Carsglass" enablecountbyexample= "FA LSE "enableupdatebyexample=" false "enabledeletebyexample=" false "enableselectbyexample=" false " Selectbyexamplequeryid= "false"/> <table tablename= "cjb_cars_high_technology" Domainobjectname= "CarsHighTech Nology "enablecountbyexample=" false "enableupdatebyexample=" false "enabledeletebyexample=" false " Enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "cjb_cars_img" DomainObject Name= "Carsimg" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" Enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "Cjb_cars_inside" DOMAINOBJ Ectname= "Carsinside" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" Enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "cjb_cars_lEase "domainobjectname=" Carslease "enablecountbyexample=" false "enableupdatebyexample=" false " Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tableNa Me= "Cjb_cars_light" domainobjectname= "Carslight" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tableNa Me= "Cjb_cars_media" domainobjectname= "Carsmedia" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tableNa Me= "Cjb_cars_refrigeration" domainobjectname= "Carsrefrigeration" enablecountbyexample= "false" Enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "False"/> <table tablename= "cjb_cars_security" domainobjectname= "carssecurity" enablecountbyexample= "fAlse "enableupdatebyexample=" false "enabledeletebyexample=" false "enableselectbyexample=" false " Selectbyexamplequeryid= "false"/> <table tablename= "cjb_cars_transmission_case" Domainobjectname= "CarsTransm Issioncase "enablecountbyexample=" false "enableupdatebyexample=" false "enabledeletebyexample=" false " Enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "Cjb_cars_wheel_brake" DOMA Inobjectname= "Carswheelbrake" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= " False "enableselectbyexample=" false "selectbyexamplequeryid=" false "/> <table tablename=" cjb_city "DOMAINOBJ Ectname= "City" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" Enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "Cjb_collection_cars" Domai Nobjectname= "Collectioncars" enablecountbyexample= "false" enableupdatebyexample= "false" EnabledeletEbyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "Cjb_col Lection_stores "Domainobjectname=" Collectionstores "enablecountbyexample=" false "enableupdatebyexample=" false " Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tableNa Me= "Cjb_dictionaries_type" domainobjectname= "Dictionariestype" enablecountbyexample= "false" EnableUpdateByExample = "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <tabl E tablename= "Cjb_dictionaries_value" domainobjectname= "Dictionariesvalue" enablecountbyexample= "false" Enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "False"/> <table tablename= "cjb_groups" domainobjectname= "groups" enablecountbyexample= "false" enableupdate Byexample= "false" enabledeletebyexample= "false" enableselectbyexample= "FAlse "selectbyexamplequeryid=" false "/> <table tablename=" cjb_groups_permissions "Domainobjectname=" GroupsPe Rmissions "enablecountbyexample=" false "enableupdatebyexample=" false "enabledeletebyexample=" false " Enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "Cjb_information_type" DOMA Inobjectname= "Informationtype" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= " False "enableselectbyexample=" false "selectbyexamplequeryid=" false "/> <table tablename=" Cjb_informations "D Omainobjectname= "informations" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= " False "enableselectbyexample=" false "selectbyexamplequeryid=" false "/> <table tablename=" Cjb_links "domainOb Jectname= "Links" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" Enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <tAble tablename= "Cjb_manager" domainobjectname= "manager" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tableNa Me= "Cjb_operation_log" domainobjectname= "Operationlog" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tableNa Me= "Cjb_operations" domainobjectname= "Operations" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tableNa Me= "Cjb_permissions" domainobjectname= "Permissions" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tableNa Me= "Cjb_permissions_operations" Domainobjectname= "PermissionsopErations "enablecountbyexample=" false "enableupdatebyexample=" false "enabledeletebyexample=" false " Enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "Cjb_provice" DomainObjectN Ame= "Provice" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" Enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "Cjb_recommend_store" Domai Nobjectname= "Recommendstore" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= " False "enableselectbyexample=" false "selectbyexamplequeryid=" false "/> <table tablename=" Cjb_roles "domainOb Jectname= "Roles" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" Enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "cjb_roles_groups" domainOb Jectname= "Rolesgroups" enablecountbyexample= "false" enableupdatebyexample= "false" EnabledeletEbyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tablename= "Cjb_ser ies "domainobjectname=" Series "enablecountbyexample=" false "enableupdatebyexample=" false "enabledeletebyexample=" False "enableselectbyexample=" false "selectbyexamplequeryid=" false "/> <table tablename=" cjb_store_apply_ent Er "domainobjectname=" Storeapplyenter "enablecountbyexample=" false "enableupdatebyexample=" false " Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tableNa Me= "Cjb_stores" domainobjectname= "Stores" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <table tableNa Me= "Cjb_stores_cars" domainobjectname= "Storescars" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" Selectbyexamplequeryid= "false" /> <table tablename= "cjb_system_message" domainobjectname= "SystemMessage" enablecountbyexample= "false" Enab Leupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= " False "/> <table tablename=" Cjb_videos "domainobjectname=" Videos "enablecountbyexample=" false "Enableupdateb Yexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/> & Lt;/context></generatorconfiguration>
Four, cmd Open the DOS window, to the root path of the project, such as my
CD D:\Program Files\eclipseworkspace\cn-chejinbao-ecommerce
Execute MVN mybatis-generator:generate (if your computer has MAVEN environment variables configured, you can use the MVN command)
Refreshing the project has the following effect.
Maven project, using MyBatis, automatically generate Pojo entity classes, DAO, mapper based on the database