Recently made a project, using MyBatis to generate code automatically, below to do a summary, is later referenced:
First, prepare in advance:
1, Tool class: Mybatis-generator-core-1.3.2.jar
2. PostgreSQL Driver: Postgresql-9.2-1003-jdbc4.jar
3. xml file
I've uploaded them to the attachment. Download Link: Download
Second, XML detailed
Our core configuration file: Mybatisgeneratorconfig.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> <Classpathentry Location= "/users/liqiu/git/study/web/soft/postgresql-9.2-1003-jdbc4.jar" /> <ContextID= "Tts2"> <jdbcconnectionDriverclass= "Org.postgresql.Driver"Connectionurl= "Jdbc:postgresql://l-***.com:5433/crm"userId= "Menpiao_dev"Password= "D**904-8DCE-**D0-BB1B-79***CC"> </jdbcconnection> <JavamodelgeneratorTargetpackage= "Com.qunar.study.entity"Targetproject= "/users/liqiu/git/study/web/src/main/java"> < Propertyname= "Enablesubpackages"value= "false" /> < Propertyname= "Trimstrings"value= "true" /> </Javamodelgenerator> <SqlmapgeneratorTargetpackage= "MyBatis"Targetproject= "/users/liqiu/git/study/web/src/main/resources/"> </Sqlmapgenerator> <Javaclientgeneratortype= "Xmlmapper"Targetpackage= "Com.qunar.study.mapper"Targetproject= "/users/liqiu/git/study/web/src/main/java"> < Propertyname= "Enablesubpackages"value= "false" /> </Javaclientgenerator> <TableSchema= "Public"TableName= "Users"Domainobjectname= "Users"></Table> <TableSchema= "Public"TableName= "Region_manager"Domainobjectname= "Regionmanager"></Table> <TableSchema= "Public"TableName= "Region"Domainobjectname= "Region"></Table> <TableSchema= "Public"TableName= "Merchant"Domainobjectname= "Merchant"></Table> <TableSchema= "Public"TableName= "State_machine"Domainobjectname= "StateMachine"></Table> <TableSchema= "Public"TableName= "Work_log"Domainobjectname= "Worklog"></Table> <TableSchema= "Public"TableName= "Contract"Domainobjectname= "Contract"></Table> <TableSchema= "Public"TableName= "notice"Domainobjectname= "Notice"></Table> <TableSchema= "Public"TableName= "Contact_person_info"Domainobjectname= "Contactpersoninfo"></Table> <TableSchema= "Public"TableName= "Express"Domainobjectname= "Express"></Table> <TableSchema= "Public"TableName= "comment"Domainobjectname= "Comment"></Table> <!--<table schema= "public" tablename= "operation" Domainobjectname= "Operation" enablecountbyexample= "true" E Nableupdatebyexample= "true" enabledeletebyexample= "true" enableselectbyexample= "true" selectbyexamplequeryid= " True "></table> - </Context></generatorconfiguration>
Third, the implementation of code:
Java-jar/users/liqiu/git/study/web/soft/mybatis-generator-core-1.3.2/lib/mybatis-generator-core-1.3.2.jar- Configfile/users/liqiu/git/study/web/soft/mybatisgeneratorconfig.xml-overwrite
Then you can see the generated code.
├──src│ ├──main│ │ ├──java│ │ │ ├──com│ │ │ │ └──qunar│ │ │ │ └──study│ │ │ │ ├──entity│ │ │ │ │ ├──comment.java│ │ │ │ │ ├──commentexample.java│ │ │ │ │ ├──contactpersoninfo.java│ │ │ │ │ ├──contactperson Infoexample.java│ │ │ │ │ ├──contract.java│ &nbs P │ │ │ │ ├──contractexample.java│ │ │  ; │ │ ├──express.java│ │ │ │ │ ├──expressexample.ja Va│ │ │ │ │ ├──merchant.java│ │ &nbs P │ │ │ ├──merchantexample.java│ │ │ │  ; │ ├──notice.java│ │ │ │ │ ├──noticeexample.java│ │ │ │ │ ├──operation.java│&n bsp; │ │ │ │ ├──operationexample.java│ │ & nbsp │ │ │ ├──region.java│ │ │ │ │ ├──regionexample.java│ │ │ │ │ ├ ──regionmanageR.java│ │ │ │ │ ├──regionmanagerexample.java│ &n Bsp │ │ │ │ ├──statemachine.java│ │ │ &n Bsp │ │ ├──statemachineexample.java│ │ │ │ │ ├──users.java│ │ │ │ │ ├──userse Xample.java│ │ │ │ │ ├──worklog.java│ │&n Bsp; │ │ │ └──worklogexample.java│ │ │ &nb Sp │ └──mapper│ │ │ │ ├──commentmapper.java │ │ │ │ ├──contactpersoninfomapper.java│ │ & nbsp │ │ ├──contractmapper.java│ │ │ │ ├──expressmapper.java│ │ │ │ ├──merchantmapper.java│&nb Sp; │ │ │ ├──noticemapper.java│ │ │ &n Bsp │ ├──operationmapper.java│ │ │ │ ├── Regionmanagermapper.java│ │ │ │ ├──regionmapper.java│ &n Bsp │ │ │ ├──statemachinemapper.java│ │ │ │ ├──usersmapper.java│ │ │ │ └──wor klogmapper.java│ │ │ └──test│ │ │ └──qunar│& nbsp; │ │ └──com│ │ │ └──web│ │  ; │ └──app.java│ │ └──resources│ │ └──mybatis│ │ ├──commentmapper.xml│ │ ├──contactperson Infomapper.xml│ │ ├──contractmapper.xml│ │ ├──expressmap Per.xml│ │ ├──merchantmapper.xml│ │ ├──noticemapper.xml│ │ ├──operationmapper.xml│ │ ├──regionmanagermapper.xml│ │ ├──regionmapper.xml│ │ ├──statemachinemapper.xml│&nbs P; │ ├──usersmapper.xml│ │ └──worklogmapper.xml
Note: The core here is the path, preferably with an absolute path