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&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 <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