MyBatis uses MAVEN to automatically generate mapper, XML, domain

Source: Internet
Author: User

The first way: Configure the Maven plugin
The new generatorconfig.xml content under Src/main/resources is 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>
<context id= "Sqlservertables" targetruntime= "MyBatis3" >
<!--generated Pojo, will implements Serializable-->
<plugin type= "Org.mybatis.generator.plugins.SerializablePlugin" ></plugin>
<commentGenerator>
<!--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:3306/thinkphp?useunicode=true&amp;characterencoding=utf-8"
Userid= "Root"
password= "Root" >
</jdbcConnection>

<!--default False to parse the JDBC DECIMAL and NUMERIC types to Integer
True to parse the JDBC DECIMAL and NUMERIC types into Java.math.BigDecimal
-
<javaTypeResolver>
<property name= "Forcebigdecimals" value= "false"/>
</javaTypeResolver>

<!--generate model models, corresponding package paths, and file storage paths (Targetproject), targetproject can specify specific paths, such as./src/main/java,
You can also use "MAVEN" to automatically generate the generated code in the Target/generatord-source directory
-
<!--<javamodelgenerator targetpackage= "Com.joey.mybaties.test.pojo" targetproject= "MAVEN" >-->
<javamodelgenerator targetpackage= "Com.kongzhong.gw2.ccc.mapper" targetproject= "./src/main/java" >
<property name= "Enablesubpackages" value= "true"/>
<!--the value returned from the database is cleared before and after the space-
<property name= "Trimstrings" value= "true"/>
</javaModelGenerator>

<!--corresponding Mapper.xml file--
<sqlmapgenerator targetpackage= "Com.kongzhong.gw2.ccc.mapper" targetproject= "./src/main/resources" >
<property name= "Enablesubpackages" value= "true"/>
</sqlMapGenerator>

<!--corresponding Mapper interface class file--
<javaclientgenerator type= "Xmlmapper" targetpackage= "Com.kongzhong.gw2.ccc.mapper" targetproject= "./src/main/ Java ">
<property name= "Enablesubpackages" value= "true"/>
</javaClientGenerator>


<!--lists all the tables to generate code, which is configured not to generate example files--
<table tablename= "Tp_user" domainobjectname= "user"
Enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false"
Enableselectbyexample= "false" Selectbyexamplequeryid= "false" >
<property name= "Useactualcolumnnames" value= "false"/>
</table>

</context>
</generatorConfiguration> execute maven command: Mybatis-generator:generate second way: Maven plugin <plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.0</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
</dependencies>
<configuration>
<overwrite>true</overwrite>
</configuration>
</plugin> new generatorconfig.xml content under Src/main/resources: <?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>
<context id= "Mysqlgenerator" targetruntime= "MyBatis3" >
<jdbcconnection driverclass= "Com.mysql.jdbc.Driver"
Connectionurl= "Jdbc:mysql://10.230.10.27:3306/gw2_dianquan?useunicode=true&amp;characterencoding=utf-8"
Userid= "Hongdian"
password= "123456"/>
<javamodelgenerator targetpackage= "Com.kongzhong.gw2.onepercentbg.domain" targetproject= "Src\main\java"/>
<sqlmapgenerator targetpackage= "Com.kongzhong.gw2.onepercentbg.mapper" targetproject= "src\main\resources"/ >
<javaclientgenerator type= "Xmlmapper" targetpackage= "com.kongzhong.gw2.onepercentbg.mapper" targetproject= "src \main\java "/>
<table tablename= "T_yizhestore_item" domainobjectname= "Items"/>
</context>
</generatorConfiguration> execute maven command: mybatis-generator:generate

MyBatis uses MAVEN to automatically generate mapper, XML, domain

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.