Mybatis逆向工程

maven

	<dependencies>
        <dependency>
            <groupId>log4jgroupId>
            <artifactId>log4jartifactId>
            <version>1.2.17version>
        dependency>
        <dependency>
            <groupId>org.mybatisgroupId>
            <artifactId>mybatisartifactId>
            <version>3.2.3version>
        dependency>
        <dependency>
            <groupId>org.mybatis.generatorgroupId>
            <artifactId>mybatis-generator-coreartifactId>
            <version>1.3.2version>
        dependency>
        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
            <version>5.1.30version>
        dependency>
        <dependency>
            <groupId>com.oraclegroupId>
            <artifactId>ojdbc6artifactId>
            <version>12.1.0.1-atlassian-hostedversion>
        dependency>
    dependencies>

xml


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>
			
			<property name="suppressAllComments" value="true" />
		commentGenerator>
		
		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/trade" userId="root"
			password="root">
		jdbcConnection>
		

		
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		javaTypeResolver>

		
		<javaModelGenerator targetPackage="com.itheima.shop.pojo"
			targetProject="E:\RocketMQ\资料\Mybatis-Reverse\src\main\java">
			
			<property name="enableSubPackages" value="false" />
			
			<property name="trimStrings" value="true" />
		javaModelGenerator>
        
		<sqlMapGenerator targetPackage="com.itheima.shop.mapper"
			targetProject="E:\RocketMQ\资料\Mybatis-Reverse\src\main\resources">
			
			<property name="enableSubPackages" value="false" />
		sqlMapGenerator>
		
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="com.itheima.shop.mapper"
			targetProject="E:\RocketMQ\资料\Mybatis-Reverse\src\main\java">
			
			<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>

		
	context>
generatorConfiguration>

启动类


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

}

你可能感兴趣的:(学习笔记,mybatis)