First, install the Eclipse plugin
Find in Help--eclipser Marketplace: Mybatis Generator 1.3.5 Installation
Second, new project
new--other--Find the following
Click Next to select the name of the project where you want to generate the file
Click Finish to close. The file Generatorconfig.xml is generated in the HHH project.
Note: The HHH project should have a database-related jar package and the package Mapper/pojo to be generated because it will be configured in the configuration file.
Third, configuration Generatorconfig.xml
[HTML]View PlainCopy
- <? 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="Testtables" targetruntime="MyBatis3">
- <commentgenerator>
- <!--whether to remove automatically generated comments true: Yes: false: No --
- <property name="suppressallcomments" value="true" />
- </commentgenerator>
- <!--database connection information: Driver class, connection address, user name, password- -
- <!--
- <jdbcconnection driverclass="Oracle.jdbc.driver.OracleDriver"
- connectionurl= "Jdbc:oracle:thin:@150.16.17.22:1521/wsbs" userid="hr "
- password="hr123">
- </jdbcconnection>-->
- <jdbcconnection driverclass="Oracle.jdbc.OracleDriver"
- connectionurl="Jdbc:oracle:thin:@150.16.17.22:1521:wsbs"
- userid="hr"
- password="hr123">
- </jdbcconnection>
- <!--default False to parse the JDBC decimal and NUMERIC types to Integer, true when JDBC decimal and
- NUMERIC type resolution to Java.math.BigDecimal-->
- <javatyperesolver>
- <property name="forcebigdecimals" value= "false" />
- </javatyperesolver>
- <!--targetproject: Generate POS Class Location--
- <javamodelgenerator targetpackage="Cn.herry.pojo"
- targetproject="hhh/src">
- <!--enablesubpackages: Do you want the schema to be a suffix of the package--
- <property name="enablesubpackages" value= "false" />
- <!--The value returned from the database is cleared before and after the space-
- <property name="trimstrings" value="true" />
- </javamodelgenerator>
- <!--targetproject:mapper Map file generated location--
- <sqlmapgenerator targetpackage="Cn.herry.mapper"
- targetproject="hhh/src">
- <!--enablesubpackages: Do you want the schema to be a suffix of the package--
- <property name="enablesubpackages" value= "false" />
- </sqlmapgenerator>
- <!--Targetpackage:mapper interface generated location--
- <javaclientgenerator type="Xmlmapper"
- targetpackage="Cn.herry.mapper"
- targetproject="hhh/src">
- <!--enablesubpackages: Do you want the schema to be a suffix of the package--
- <property name="enablesubpackages" value= "false" />
- </javaclientgenerator>
- <!--specifying database tables --
- <!--<table tablename= "items" ></table> -
- <table tablename="Demo"></table>
- </Context>
- </generatorconfiguration>
Iv. automatic generation of files such as Mapper.java and Mapper.xml
Right-click Generatorconfig.xml and select the following:
After that, you can see the generated files under the package.
end!
Eclipse Plug-ins: How to use MyBatis generator