Mybatis逆向工程

maven

xml 复制代码
	<dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.30</version>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>12.1.0.1-atlassian-hosted</version>
        </dependency>
    </dependencies>

xml

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="testTables" targetRuntime="MyBatis3">
		<commentGenerator>
			<!-- 是否去除自动生成的注释 true:是 : false:否 -->
			<property name="suppressAllComments" value="true" />
		</commentGenerator>
		<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/trade" userId="root"
			password="root">
		</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>

		<!-- targetProject:生成PO类的位置 -->
		<javaModelGenerator targetPackage="com.itheima.shop.pojo"
			targetProject="E:\RocketMQ\资料\Mybatis-Reverse\src\main\java">
			<!-- enableSubPackages:是否让schema作为包的后缀 -->
			<property name="enableSubPackages" value="false" />
			<!-- 从数据库返回的值被清理前后的空格 -->
			<property name="trimStrings" value="true" />
		</javaModelGenerator>
        <!-- targetProject:mapper映射文件生成的位置 -->
		<sqlMapGenerator targetPackage="com.itheima.shop.mapper"
			targetProject="E:\RocketMQ\资料\Mybatis-Reverse\src\main\resources">
			<!-- enableSubPackages:是否让schema作为包的后缀 -->
			<property name="enableSubPackages" value="false" />
		</sqlMapGenerator>
		<!-- targetPackage:mapper接口生成的位置 -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="com.itheima.shop.mapper"
			targetProject="E:\RocketMQ\资料\Mybatis-Reverse\src\main\java">
			<!-- enableSubPackages:是否让schema作为包的后缀 -->
			<property name="enableSubPackages" value="false" />
		</javaClientGenerator>
		<!-- 指定数据库表 -->
		<table schema="" tableName="trade_coupon"></table>
		<table schema="" tableName="trade_goods"></table>
		<table schema="" tableName="trade_goods_number_log"></table>
		<table schema="" tableName="trade_order"></table>
		<table schema="" tableName="trade_pay"></table>
		<table schema="" tableName="trade_user"></table>
		<table schema="" tableName="trade_user_money_log"></table>
        <table schema="" tableName="trade_mq_consumer_log"></table>
        <table schema="" tableName="trade_mq_producer_temp"></table>

		<!-- 有些表的字段需要指定java类型
		<table schema="" tableName="">
			<columnOverride column="" javaType="" />
		</table> -->
	</context>
</generatorConfiguration>

启动类

java 复制代码
public class GeneratorSqlmap {

	public void generator() throws Exception{

		List<String> warnings = new ArrayList<String>();
		boolean overwrite = true;
		File configFile = new File("\\resources\\generatorConfig.xml");//xml文件位置
		ConfigurationParser cp = new ConfigurationParser(warnings);
		Configuration config = cp.parseConfiguration(configFile);
		DefaultShellCallback callback = new DefaultShellCallback(overwrite);
		MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
				callback, warnings);
		myBatisGenerator.generate(null);

	}
	public static void main(String[] args) throws Exception {
		try {
			GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
			generatorSqlmap.generator();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
相关推荐
sunddy_x2 小时前
Spring事务
java·spring·mybatis
阿杰 AJie2 小时前
MyBatis-Plus 的内置方法
java·数据库·mybatis
橘橙黄又青3 小时前
MyBatis篇
数据库·oracle·mybatis
一直都在5723 小时前
Spring3整合MyBatis实现增删改查操作
前端·vue.js·mybatis
迪霸戈3 小时前
MyBatis动态SQL避坑:为什么List用`[0]`而不是`get(0)`
sql·list·mybatis
不凡而大米、3 小时前
报错:传入的请求具有过多的参数。该服务器支持最多2100个参数
java·开发语言·mybatis
BD_Marathon3 小时前
MyBatis的一级缓存
spring·缓存·mybatis
啊吧怪不啊吧4 小时前
极致性能的服务器Redis之Hash类型及相关指令介绍
大数据·数据库·redis·sql·mybatis·哈希算法
小马爱打代码20 小时前
MyBatis:反射模块详解
mybatis
Klong.k1 天前
Mybatis-plus中Save()方法的注意点
mybatis