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();
		}
	}

}
相关推荐
晴空๓4 小时前
Spring Boot项目如何使用MyBatis实现分页查询
spring boot·后端·mybatis
一缕叶19 小时前
mybatis(78/134)
mybatis
安清h1 天前
【基于SprintBoot+Mybatis+Mysql】电脑商城项目之用户注册
数据库·后端·mysql·spring·mybatis
yang_shengy1 天前
【JavaEE】Spring(5):Mybatis(上)
spring·java-ee·mybatis
字节全栈_PVK2 天前
Flask数据的增删改查(CRUD)_flask删除数据自动更新
数据库·flask·mybatis
花心蝴蝶.3 天前
MyBatis 入门
java·spring boot·后端·mybatis
or77iu_N3 天前
SpringBoot 中的测试jar包knife4j(实现效果非常简单)
java·开发语言·spring boot·后端·mybatis·jar
苏-言3 天前
SSM框架探秘:Spring 整合 Mybatis 框架
java·spring·mybatis
yang_shengy4 天前
【JavaEE】Spring(6):Mybatis(下)
spring·java-ee·mybatis
康惠桀4 天前
Mybatis-plus缓存
缓存·mybatis