MyBatis Reverse Code generation configuration

Source: Internet
Author: User

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"/&GT </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> &lt ;! --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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.