MyBatis generator automatically generates mapper files and model

Source: Internet
Author: User

Using MyBatis generator can generate mybatis corresponding mapper and model according to the database table, the generated example can satisfy the general single table operation, use MyBatis annotation, The @mbggenerated can be used to overwrite the generated code at the next build, without affecting the manually added query (the Eclipse plugin that needs to be used, IntelliJ does not currently have a similar plugin), in the use of IntelliJ, can use the free MyBatis plug-in, can quickly locate in the Mapper class to the corresponding XML, very advantageous to SQL view;

MyBatis Configuration:

<?XML version= "1.0" encoding= "UTF-8"?>  <!DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis Generator Configuration 1.0//en" "Htt P://mybatis.org/dtd/mybatis-generator-config_1_0.dtd "><generatorconfiguration><Classpathentry Location= "${jdbc.driverlocation}" />    <!--Database-driven -    <Classpathentry Location= "${jdbc.driverlocation}" />    <ContextID= "Db2tables"Targetruntime= "MyBatis3">        <Commentgenerator>        <!--@mbggenerated the generated configuration -            < Propertyname= "Suppressdate"value= "false" />         <!--whether to remove automatically generated comments true: Yes: false: No -            < Propertyname= "Suppressallcomments"value= "true" />        </Commentgenerator>                <!--database link URL, user name, password -        <jdbcconnectionDriverclass= "Com.mysql.jdbc.Driver"Connectionurl= "${jdbc.connectionurl}"userId= "${jdbc.userid}"Password= "${jdbc.password}" />                <Javatyperesolver>            < Propertyname= "Forcebigdecimals"value= "false" />        </Javatyperesolver>        <!--Build the package name and location of the model -        <JavamodelgeneratorTargetpackage= "${modelpackage_name}"Targetproject= "Mybatis_generator">            < Propertyname= "Enablesubpackages"value= "true" />            < Propertyname= "Trimstrings"value= "false" />        </Javamodelgenerator>        <!--Build the package name and location of the mapping file -        <SqlmapgeneratorTargetpackage= "${mapperpackage_name}"Targetproject= "Mybatis_generator">            < Propertyname= "Enablesubpackages"value= "true" />        </Sqlmapgenerator>        <!--generate DAO's package name and location -        <Javaclientgeneratortype= "Xmlmapper"Targetpackage= "${daopackage_name}"Targetproject= "Mybatis_generator">            < Propertyname= "Enablesubpackages"value= "true" />        </Javaclientgenerator>        <!--which tables to generate -        <TableTableName= "${table_name}"Domainobjectname= "${model_name}"Enablecountbyexample= "true"Enableupdatebyexample= "true"Enabledeletebyexample= "true"Enableselectbyexample= "true"Selectbyexamplequeryid= "true">        </Table>    </Context></generatorconfiguration>

Config configuration:

jdbc.driverlocation=e://mysql-connector-java-5.1.18-bin.jarjdbc.driverclass= Com.mysql.jdbc.driverjdbc.connectionurl=jdbc:mysql://ip:port/test?useunicode=true& Characterencoding=utf-8jdbc.userid=jdbc.password= #模型的包名modelpackage_name = #dao的包名daopackage_name =# XML storage location mapperpackage_name=mapper# table name table_name=temp# The name of the generated model Model_name=temp

Attention:

Generate MyBatis corresponding model and DAO Mapper.xml based on database table, in addition to configuration item configuration, if you want to build into another project (currently only generated in
Under this project), you need to modify the Targetproject property of the Generator-config.xml (configured in the properties
Generator-config.xml can not be effective, so can only be manually changed, Targetproject property as long as the other project name is good)

MyBatis generator automatically generates mapper files and model

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.