Since MyBatis is a semi-automatic ORM framework, its work is mainly to configure the mapping mapping file, in order to reduce manual mapping file, you can use the MyBatis generator, automatically generate entity class, DAO interface and its mapping file, And then copy directly to the project to make a slight modification can be used directly.
The generator directory is as follows:
First go to the Lib folder, the directory is as follows:
(pictured on file: http://download.csdn.net/detail/qiwei31229/9790909)
Main changes 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-driven<classpathentry location= "Mysql-connector-java-5.1.25-bin.jar"/> <context id= "DB2Tables" TargetRuntime= "M YBatis3 "> <commentGenerator> <property name=" Suppressdate "value=" true "/><!--whether to remove automatically generated comments true: Yes: false: No --<property name= "Suppressallcomments" value= "true"/> </commentGenerator> <!--database link URL, user name, Password--<jdbcconnection driverclass= "Com.mysql.jdbc.Driver" connectionurl= "Jdbc:mysql://127.0.0.1/test" userId = "root" password= "123456" > </jdbcConnection> <javaTypeResolver> <property Name= "Forcebigdecimals" value= "false"/> </javaTypeResolver><!--generate the package name and location of the model--<javamodelgenerator targetpackage= "Com.shaw.cn.domain" targetproject= "src" > <property name= "Enablesu Bpackages "value=" true "/> <property name=" trimstrings "value=" true "/> </javamodelgenerat Or><!--generate the package name and location of the mapping file--<sqlmapgenerator targetpackage= "com.shaw.cn.mapping" targetproject= "src" > <property name= "enablesubp Ackages "value=" true "/> </sqlMapGenerator><!--Generate DAO's package name and location--<javaclientgenerator type= "Xmlmapper" targetpackage= "Com.shaw.cn.IDao" targetproject= "src" > <propert Y name= "enablesubpackages" value= "true"/> </javaClientGenerator><!--the table TableName to be generated is the table name or view name in the database Domainobjectname is the entity class name--<table tablename= "user_t" domainobjectname= "user" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" Selectbyexamplequeryid= "false" ></table> < /context> </generatorConfiguration>
Note that the table needs to be created in a specific database now, and then shift+ the right mouse button in the Lib folder to open the console command input:
Java-jar Mybatis-generator-core-1.3.2.jar-configfile Generatorconfig.xml-overwrite
This allows you to see the code for the developed directory in SRC.
MyBatis automatic generation of entity classes, DAO interfaces, and Mapping mapping files