1、创建maven项目,导包
<build> <plugins> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.5</version> <configuration> <verbose>true</verbose> <overwrite>true</overwrite> <configurationFile>E:hibernatesrcmain esourcesmybatisgeneratorConfig.xml</configurationFile> </configuration> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>6.0.6</version> </dependency> </dependencies> </plugin> </plugins> </build>
2、在resources下创建generatorConfig.xml
<?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="MySQL2Tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressAllComments" value="true" /> <property name="addRemarkComments" value="true" /> </commentGenerator> <!--数据源--> <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://10.147.255.18:3306/xq_core_jc1" userId="xq_core_jc1" password="xq_core_jc1"> </jdbcConnection> <javaTypeResolver > <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <javaModelGenerator targetPackage="dto" targetProject="E:hibernatesrcmainjava"> <property name="enableSubPackages" value="false" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <sqlMapGenerator targetPackage="mapper" targetProject="E:hibernatesrcmainjava"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <javaClientGenerator type="XMLMAPPER" targetPackage="dao" targetProject="E:hibernatesrcmainjava"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <table tableName="t_c_wh_monthly_bill" domainObjectName="TcWhMonthlyBill"/> </context> </generatorConfiguration>
3、添加maven配置
(mybatis-generator:generate -e)
4、双击运行
5、大功告成