IDEA:在maven下实现mybatis逆向工程

IDEA:在maven下实现mybatis逆向工程_第1张图片

1.pom文件


<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>

    <groupId>mybatisgroupId>
    <artifactId>nxgcartifactId>
    <version>1.0-SNAPSHOTversion>

    <dependencies>
        
        <dependency>
            <groupId>org.mybatis.generatorgroupId>
            <artifactId>mybatis-generator-coreartifactId>
            <version>1.3.5version>
        dependency>
        
        <dependency>
            <groupId>org.mybatisgroupId>
            <artifactId>mybatisartifactId>
            <version>3.4.5version>
        dependency>
        
        <dependency>
            <groupId>com.oraclegroupId>
            <artifactId>ojdbc6artifactId>
            <version>11.2.0.1.0version>
        dependency>
    dependencies>
project>

2.配置文件nxgc_config.xml




<generatorConfiguration>
    <context id="testTables" targetRuntime="MyBatis3">
        <commentGenerator>
            
            <property name="suppressAllComments" value="true" />
        commentGenerator>


        
        
        
                        
                        
                        
        
        
        <jdbcConnection
                driverClass="oracle.jdbc.driver.OracleDriver"
                connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:orcl"
                userId="LYH"
                password="lyh123">
        jdbcConnection>


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


        
        <javaModelGenerator targetPackage="com.ssm.pojo"
                            targetProject=".\src\main\java">
            
            <property name="enableSubPackages" value="false" />
            
            <property name="trimStrings" value="true" />
        javaModelGenerator>


        
        <sqlMapGenerator targetPackage="com.ssm.dao"
                         targetProject=".\src\main\java">
            
            <property name="enableSubPackages" value="false" />
        sqlMapGenerator>


        
        <javaClientGenerator type="XMLMAPPER"
                             targetPackage="com.ssm.dao"
                             targetProject=".\src\main\java">
            
            <property name="enableSubPackages" value="false" />
        javaClientGenerator>


        
        <table tableName="USER_MEG">table>
    context>
generatorConfiguration>

3.主程序mybatis_nxgc.java

package com.ssm;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class mybatis_nxgc {

    public static void main(String[] args) throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {
        List warnings = new ArrayList();
        boolean overwrite = true;
        File configFile = new File("D:\\IntelliJ_idea\\nxgc\\src\\main\\resources\\nxgc_config.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);
    }
}

完成以上三步之后,就可以运行主程序自动生成。
IDEA:在maven下实现mybatis逆向工程_第2张图片

你可能感兴趣的:(Mybatis)