Generator automatically generates mybatis configuration and class information

Source: Internet
Author: User

When I use mybatis to write the ing between a class and a data table, there are too many column names in the table and there are also many problems. It is complicated to write the corresponding column names and Class Object Attributes one by one.

To facilitate and reduce errors, you can use the code generator provided by mybatis to automatically generate xml ing files, models, maps, and other information for mybatis.

Mybatis official website to download a mybatis-generator-core-1.3.2-bundle, In the compressed package find the jar package under Lib. Write mybatis. xml and execute it.

 

 

 

<Generatorconfiguration>
<! -- Here is the jar package address for loading the JDBC driver -->
<Classpathentry location = "C: \ Users \ administrator. WJ-20131202XSPS \ Desktop \ mybatis-generator-core-1.3.2 \ Lib \ mysql-connector-java-5.1.7-bin.jar"/>

<Context ID = "db2tables" targetruntime = "mybatis3">

<! -- Whether to remove automatically generated comments: true: Yes, false: No -->
<Commentgenerator>
<Property name = "suppressallcomments" value = "true"/>
</Commentgenerator>

<! -- Database connection information: Driver Class, connection address, user name, password -->
<Jdbcconnection driverclass = "com. MySQL. JDBC. Driver"
Connectionurl = "JDBC: mysql: // localhost/workloads" userid = "root" Password = "mysql0000366">
</Jdbcconnection>

<! -- The default value is false. The JDBC decimal and numeric types are parsed to integer true, and the JDBC decimal and numeric types are parsed to Java. Math. bigdecimal -->
<Javatyperesolver>
<Property name = "forcebigdecimals" value = "false"/>
</Javatyperesolver>

<! -- Application entity generation information -->
<Javamodelgenerator targetpackage = "com. tly. Entity"
Targetproject = "C: \ table">
<Property name = "enablesubpackages" value = "true"/>
<Property name = "trimstrings" value = "true"/>
</Javamodelgenerator>

<! -- Sqlmapper XML file generation information, including the generated path and other targetprojects, indicating the location where the generated file is stored -->
<Sqlmapgenerator targetpackage = "com. tly. Mapping" targetproject = "C: \ table">
<Property name = "enablesubpackages" value = "true"/>
</Sqlmapgenerator>

<Javaclientgenerator type = "xmlmapper"
Targetpackage = "com. tly. Dao" targetproject = "C: \ table">
<Property name = "enablesubpackages" value = "true"/>
</Javaclientgenerator>
<! -- Ing between tables in the database and objects in the program -->
<Table tablename = "project" domainobjectname = "classrecord" enablecountbyexample = "false" enableupdatebyexample = "false"
Enabledeletebyexample = "false" enableselectbyexample = "false" selectbyexamplequeryid = "false">
</Table>
<Table tablename = "project_score" domainobjectname = "parameter" enablecountbyexample = "false" enableupdatebyexample = "false"
Enabledeletebyexample = "false" enableselectbyexample = "false" selectbyexamplequeryid = "false">
</Table>
</Context>
</Generatorconfiguration>

 

 

In cmd enter Java-jar mybatis-generator-core-1.3.2.jar-configfile generator. XML-overwrite, the path here is absolute, for convenience, we can create a BAT file in the folder where the mybatis-generator-core-1.3.2 is located, enter

TXT code
  1. @ Echo off
  2. Echo =========== mybatis starts to generate code ============================
  3. Java-jar mybatis-generator-core-1.3.2.jar-configfile generator. XML-overwrite
  4. Echo =========== mybatis code generation complete ============================

 

Finally, we can press shift and right-click to open the command window in the folder and directly run the BAT file.

 

 

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.