Since MyBatis belongs to a semi-automatic ORM framework, the main work will be to write mapping mapping files, but because the handwriting map file is prone to error, the data found that there are ready-made tools to automatically generate the underlying model classes, DAO interface classes and even mapping mapping files.
Generate the required files and jar packages for your code:
(File: http://download.csdn.net/detail/u012909091/7206091)
There are jar packages for the MyBatis framework, database driver jar packages, and MyBatis generator jar packages. The Generatorconfig.xml is a file that needs to be configured by us, configured as follows:
1 <?XML version= "1.0" encoding= "UTF-8"?> 2 <!DOCTYPE generatorconfiguration3 Public "-//mybatis.org//dtd mybatis Generator Configuration 1.0//en"4 "Http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> 5 <generatorconfiguration> 6 <!--Database-driven -7 <Classpathentry Location= "Mysql-connector-java-5.1.25-bin.jar"/> 8 <ContextID= "Db2tables"Targetruntime= "MyBatis3"> 9 <Commentgenerator> Ten < Propertyname= "Suppressdate"value= "true"/> One <!--whether to remove automatically generated comments true: Yes: false: No - A < Propertyname= "Suppressallcomments"value= "true"/> - </Commentgenerator> - <!--database link URL, user name, password - the <jdbcconnectionDriverclass= "Com.mysql.jdbc.Driver"Connectionurl= "Jdbc:mysql://192.168.7.201:12340/program_shopcart"userId= "sa"Password= "1234"> - </jdbcconnection> - <Javatyperesolver> - < Propertyname= "Forcebigdecimals"value= "false"/> + </Javatyperesolver> - <!--Build the package name and location of the model - + <JavamodelgeneratorTargetpackage= "Wyp.db.test.domain"Targetproject= "src"> A < Propertyname= "Enablesubpackages"value= "true"/> at < Propertyname= "Trimstrings"value= "true"/> - </Javamodelgenerator> - <!--Build the package name and location of the mapping file - - <SqlmapgeneratorTargetpackage= "Wyp.db.test.mapping"Targetproject= "src"> - < Propertyname= "Enablesubpackages"value= "true"/> - </Sqlmapgenerator> in <!--generate DAO's package name and location - - <Javaclientgeneratortype= "Xmlmapper"Targetpackage= "Wyp.db.test.IDao"Targetproject= "src"> to < Propertyname= "Enablesubpackages"value= "true"/> + </Javaclientgenerator> - <!--the table TableName to be generated is the name of the table or view in the database Domainobjectname is the entity class name - the <TableTableName= "Account_group"Domainobjectname= "Account_group"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"></Table> * <TableTableName= "Account_grouppermissionassign"Domainobjectname= "Account_grouppermissionassign"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"></Table> $ <TableTableName= "Account_permission"Domainobjectname= "Account_permission"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"></Table>Panax Notoginseng <TableTableName= "Account_role"Domainobjectname= "Account_role"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"></Table> - <TableTableName= "Account_rolepermissionassign"Domainobjectname= "Account_rolepermissionassign"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"></Table> the <TableTableName= "Account_user"Domainobjectname= "Account_user"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"></Table> + <TableTableName= "Account_usergroupassign"Domainobjectname= "Account_usergroupassign"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"></Table> A <TableTableName= "Account_userpermissionassign"Domainobjectname= "Account_userpermissionassign"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"></Table> the <TableTableName= "Account_userroleassign"Domainobjectname= "Account_userroleassign"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"></Table> + </Context> - </generatorconfiguration>
Generatorconfig.xml
When these are completed, simply open the console and enter the Lib directory to execute the script:
Java-jar Mybatis-generator-core-1.3.2.jar-configfile Generatorconfig.xml-overwrite
Can.
MyBatis---Use MyBatis generator to generate DTOs, Dao, Mapping