赞
踩
除了有关路径的写法不同,其余一致
Mac:src/main/java
Windows:src\main\java
plugin自行放入即可
- <!--逆向工程-->
- <dependency>
- <groupId>org.mybatis.generator</groupId>
- <artifactId>mybatis-generator-core</artifactId>
- <version>1.3.5</version>
- </dependency>
-
- <!-- 逆向工程 -->
- <plugin>
- <groupId>org.mybatis.generator</groupId>
- <artifactId>mybatis-generator-maven-plugin</artifactId>
- <version>1.3.5</version>
- <dependencies>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>8.0.20</version>
- </dependency>
- </dependencies>
- <configuration>
- <!--配置文件的路径-->
- <configurationFile>
- src/main/resources/generatorConfig.xml
- </configurationFile>
- <overwrite>true</overwrite>
- </configuration>
- </plugin>
路径为:src//main//resources//generatorConfig.xml
和application.yml路径一致
- <?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>
- <!-- 是否去除自动生成的注释 true:是 : false:否 -->
- <property name="suppressAllComments" value="true" />
- </commentGenerator>
- <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
- <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
- connectionURL="jdbc:mysql://localhost:3306/test" userId="root"
- password="12345678">
- </jdbcConnection>
- <!-- <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
- connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:yycg"
- userId="yycg"
- password="yycg">
- </jdbcConnection> -->
-
- <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
- NUMERIC 类型解析为java.math.BigDecimal -->
- <javaTypeResolver>
- <property name="forceBigDecimals" value="false" />
- </javaTypeResolver>
-
- <!-- 注意生成的路径
- Mac:./src/main/java
- window:.\src\main\java
- -->
-
- <!-- targetProject:生成PO类的位置 -->
- <javaModelGenerator targetPackage="com.func.pojo"
- targetProject="./src/main/java">
- <!-- enableSubPackages:是否让schema作为包的后缀 -->
- <property name="enableSubPackages" value="false" />
- <!-- 从数据库返回的值被清理前后的空格 -->
- <property name="trimStrings" value="true" />
- </javaModelGenerator>
- <!-- targetProject:mapper映射文件生成的位置 -->
- <sqlMapGenerator targetPackage="com.func"
- targetProject="./src/main/resources/mappers">
- <!-- enableSubPackages:是否让schema作为包的后缀 -->
- <property name="enableSubPackages" value="false" />
- </sqlMapGenerator>
- <!-- targetPackage:mapper接口生成的位置 -->
- <javaClientGenerator type="XMLMAPPER"
- targetPackage="com.func.mapper"
- targetProject="./src/main/java">
- <!-- enableSubPackages:是否让schema作为包的后缀 -->
- <property name="enableSubPackages" value="false" />
- </javaClientGenerator>
- <!-- 指定数据库表 -->
- <!-- <table schema="" tableName="sys_user"></table>
- <table schema="" tableName="orders"></table> -->
- <table schema="" tableName="user_info"></table>
- <!-- <table schema="" tableName="tb_content_category"></table>-->
- <!-- <table schema="" tableName="tb_item"></table>-->
- <!-- <table schema="" tableName="tb_item_cat"></table>-->
- <!-- <table schema="" tableName="tb_item_desc"></table>-->
- <!-- <table schema="" tableName="tb_item_param"></table>-->
- <!-- <table schema="" tableName="tb_item_param_item"></table>-->
- <!-- <table schema="" tableName="tb_order"></table>-->
- <!-- <table schema="" tableName="tb_order_item"></table>-->
- <!-- <table schema="" tableName="tb_order_shipping"></table>-->
- <!-- <table schema="" tableName="tb_user"></table>-->
-
- <!-- 有些表的字段需要指定java类型
- <table schema="" tableName="sys_user">
- <columnOverride column="user_id" javaType="Long" />
- </table> -->
- </context>
- </generatorConfiguration>
- package com.func.util;
-
- import org.mybatis.generator.api.MyBatisGenerator;
- import org.mybatis.generator.config.Configuration;
- import org.mybatis.generator.config.xml.ConfigurationParser;
- import org.mybatis.generator.internal.DefaultShellCallback;
-
- import java.io.File;
- import java.util.ArrayList;
- import java.util.List;
-
- public class GeneratorUtil {
- public static void main(String[] args) throws Exception {
- //mac用//,window用\\
- File f = new File("src//main//resources//generatorConfig.xml");
- List<String> warnings = new ArrayList<String>();
- ConfigurationParser cp = new ConfigurationParser(warnings);
- Configuration config = cp.parseConfiguration(f);
- DefaultShellCallback callBack = new DefaultShellCallback(true);
- MyBatisGenerator generator = new MyBatisGenerator(config, callBack, warnings);
- generator.generate(null);
- }
- }
在XML里写好表名,执行该类即可
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。