Use Maven plugin +mabatis-generator to generate MyBatis files under Eclipse

Source: Internet
Author: User
Tags generator one table

There are a lot of things on the web about the database table mapping configuration that Mabatis-generator automatically generates Mabatis and the usage of beans and DAO, broadly divided into these types: Eclipse plug-in generation, jar package generation, MAVEN plugin + Mabatis-generator generated, this is only the last usage. 1. Configure Maven Pom.xml files

Add the following plugins to the Pom.xml:

   <build>
       </plugins> ...
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId> mybatis-generator-maven-plugin</artifactid>
                <version>1.3.2</version>
                < configuration>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin> ...
        </plugins>
    </build>

Configure the MAVEN plug-in, below need to configure the plug-in needs mybatis-generator configuration file 2. Configure Mybatis-generator Profile

Add the configuration file to resource:

Generatorconfig.xml content:

<?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> <!--ojdbc Jar-- <classpathentry location= "E:/maven/mvn_repository/com/oracle/ojdbc14/14/ojdbc14-14.jar"/> <contex T id= "my" targetruntime= "MyBatis3" > <commentGenerator> <property name= "Suppressdate" value
        = "false"/> <property name= "suppressallcomments" value= "true"/> </commentGenerator> <!--database connection information--<jdbcconnection driverclass= "Oracle.jdbc.driver.OracleDriver" connecti Onurl= "JDBC:ORACLE:THIN:@192.168.1.112:1521:ORCL" userid= "KY" password= "KY"/> <!--model Generation Road Size--<javamodelgenerator targetpackage= "Com.dg.bean" targetproject= "E:/myworkspace/ssmdemo/src/main/java "> <property name=" enablesubpackages "value=" true "/> &
        Lt;property name= "Trimstrings" value= "true"/> </javaModelGenerator> <!--map XML file generation path-- <sqlmapgenerator targetpackage= "com.dg.mapping" targetproject= "E:/myworkspace/ssmdemo/src/main/java"  > <property name= "enablesubpackages" value= "true"/> </sqlMapGenerator> <!-- The Dao build path associated with the XML file (the generated file name is ***mapper.java by default and is used to rename it to ***dao.java)-<javaclientgenerator targetpackage= "COM.DG . Dao "targetproject=" E:/myworkspace/ssmdemo/src/main/java "type=" Xmlmapper "> <property name=
        "Enablesubpackages" value= "true"/> </javaClientGenerator> <!--target table, if you have more than one table, configure the copy individually- <table tablename= "Order_info" domainobjectname= "Orderinfobean" enablecountbyexample= "false" enableUp
  Datebyexample= "false"          Enabledeletebyexample= "false" enableselectbyexample= "false" Selectbyexamplequeryid= "false" > </table> </context> </generatorConfiguration>
3. Generate Code

In Eclipse, select the Pom.xml file, right-click the run As-->maven build...--> enter in the Goals box: Mybatis-generator:generate,maven will download the plugin first, Then generate the code.

Look at the effect:

Then, according to our habits will be generated by the name of the file (note the XML file namespace do not forget to change).

Related Article

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.