Idea generates objects for database tables through MyBatis generator

Source: Internet
Author: User
Tags generator

1. file-->new-->module-->maven-->next--> input GroupID, Artifactid, and version-->next--> input Module name , Content root, and module file Location-->finish to complete the creation.

2. Run/debug Configurations--"+"--->maven---> enter name, working directory and command line (mybatis-generator: Generate)---> "OK"

3. Edit the Generatorconfig.xml file in the resource directory as follows:

<!DOCTYPE generatorconfiguration Public"-//mybatis.org//dtd mybatis Generator Configuration 1.0//en"        "HTTP://MYBATIS.ORG/DTD/MYBATIS-GENERATOR-CONFIG_1_0.DTD"><generatorConfiguration> <classpathentry location="C:\Users\xxx\.m2\repository\mysql\mysql-connector-java\5.1.22\mysql-connector-java-5.1.22.jar"/> <!--Import Properties configuration-<context id="default"Targetruntime="MyBatis3"> <property name="javafileencoding"Value="UTF-8"/> <jdbcconnection Driverclass="Com.mysql.jdbc.Driver"Connectionurl="Jdbc:mysql://localhost:8080/union?useunicode=true&amp;characterencoding=utf-8"userId="Root"Password="Root"/> <!--model Builder, which is used to generate classes containing primary key keys, record classes, and query example Class Targetpackage the package name of the generated model generation Targetproject Specify the path under which the item is located-<Javamodelgenerator targetpackage="com.guwz.union.entity"Targetproject="Src/main/java"> <!--Add a constructor to the model--<property name="enablesubpackages"Value="true"/> <!--Add a parent class to the model-<!--<property Name="Rootclass"Value="Com.itfsw.base"/>--> </javaModelGenerator> <!--The mapper mapping file generates the corresponding Sqlmap file for each database table--and &LT;SQ Lmapgenerator targetpackage="Mappings"Targetproject="src/main/resources"/> <!--client-side code that generates easy-to-use code for model objects and XML configuration files type="Annotatedmapper", generate Java Model and annotation-based mapper object type="Mixedmapper", generate the annotation-based Java Model and the corresponding Mapper object type="Xmlmapper", generate Sqlmap XML file and stand-alone mapper interface--<javaclientgenerator targetpackage="Com.guwz.union.dao"Targetproject="Src/main/java"type="Xmlmapper"/> <!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ The table to be automatically generated ++++++++++++++++++++++++++++ +++++++++++++++++++++++++++--<table tablename="Table"> <generatedkey column="ID"Sqlstatement="MYSQL"identity="true"/> </table> </context></generatorConfiguration>
View Code

4. Run Generator configuration

Idea generates objects for database tables through MyBatis generator

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.