First step: Install the Mybatis-generator plugin first;
Step two: Create a MAVEN project and create a generatorconfig.xml under Src/main/resources
Step Three: Configure the Generatorconfig.xml, which is configured as follows:
<?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><!--Introducing configuration Files-->< Properties Resource= "Jdbc.properties"/><!--Develop data connection driver jar address--><classpathentry location= "${path}"/> <!--a database corresponding to a context--><context id= "Db_context" ><!--comment--><commentgenerator><property Name= "Suppressallcomments" value= "true"/><!--uncomment--<property name= "suppressdate" value= "FAL Se "/> <!--generate annotation generation timestamp-</commentGenerator><!--jdbc Connection--><jdbcconnection driverclass=" ${ Driverclassname} "connectionurl=" ${url1} "userid=" ${username} "password=" ${password} "/><javatyperesolver > <!--whether to use BigDecimal, false to automatically convert the following types (Long, Integer, short, etc)--<property name = "Forcebigdecimals" value= "false"/> </javaTypeResolver> <!--generate entity class address--><javamodelgenerator targetpackage= "Com.ssm.domain" Targetproject = "${projectname}" > <!--whether to add a new layer schema,eg:fase path under the current path Com.oop.eksp.user.model, True:com.oop.eksp.user.model. [SchemaName]-<property name= "Enablesubpackages" value= "false"/> <!--for string class Type of field is trim called when set--<property name= "Trimstrings" value= "true"/> </javaModelGenerator> < ;! --Generate Mapxml files--<sqlmapgenerator targetpackage= "Com.ssm.dao" targetproject= "${projectname}" ><property Name= "Enablesubpackages" value= "false"/> </sqlMapGenerator><!--generate mapxml corresponding to the client, which is the interface DAO--and <ja Vaclientgenerator targetpackage= "Com.ssm.dao" targetproject= "${projectname}" type= "Xmlmapper" ><property name = "Enablesubpackages" value= "false"/> </javaClientGenerator> <!--configuration table information-<!--schema is the database name Tablena me for the corresponding database table Domainobjectname is the entity class to be generated ENABle*byexample whether to generate example class--<table schema= "${database}" Tablename= "Sys_user" domainobjectn Ame= "User" enablecountbyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" Enableupdatebyexample= "false" > <!--ignore columns, do not generate bean fields--<ignorecolumn column= "FRED "/> <columnoverride column=" id "property=" id "javatype=" java.lang.Long "/></table><table schema=" $ {database} "tablename=" Sys_attachment "domainobjectname=" Attachment "enablecountbyexample=" false "Enabledelete Byexample= "false" enableselectbyexample= "false" enableupdatebyexample= "false" > <!--ignore column, do not generate Bean Fields--<ignorecolumn column= "FRED"/> <columnoverride column= "id" property= "id" javatype= "ja Va.lang.Long "/><columnoverride column=" Createtime "property=" Create_time "javatype=" Java.util.Date "/> <columnoverride column= "creater" properTy= "creater" javatype= "Java.lang.Long"/></table></context></generatorconfiguration> The jdbc.properties configuration is as follows:
driverclassname=com.mysql.jdbc.driverurl=jdbc\:mysql\://localhost\:3306/test?useunicode\=true& characterencoding\=utf-8username=rootpassword=***maxidle=5maxactive=40defaultautocommit= falsetimebetweenevictionrunsmillis=3600000minevictableidletimemillis=3600000url1=jdbc:mysql://localhost:3306/ Testpath=e:/mysql-connector-java-5.1.18.jarprojectname=ssmdatabase=test
Once configured, you are ready to test.
Fourth step: Test, right click Generatorconfig.xml generate Mybatis/ibatis artifacts, and then refresh the project to detect there is no code.
MyBatis Reverse Code generation configuration