Mybatis第九篇【基于Maven在Idea下Mybatis逆向工程】

前言

在Intellij idea下,没有学习Maven的情况下使用Mybatis的逆向工程好像有点复杂,资料太少了…找到的资料好像也行不通…

于是学完Maven之后,我就再来更新Idea下使用Mybatis的逆向工程配置…

借鉴博文:http://blog.csdn.net/for_my_life/article/details/51228098

修改pom.xml文件

向该工程添加逆向工程插件..



<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>asdfgroupId>
    <artifactId>asdfartifactId>
    <version>1.0-SNAPSHOTversion>
    <build>
        <finalName>zhongfuchengfinalName>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generatorgroupId>
                <artifactId>mybatis-generator-maven-pluginartifactId>
                <version>1.3.2version>
                <configuration>
                    <verbose>trueverbose>
                    <overwrite>trueoverwrite>
                configuration>
            plugin>
        plugins>
    build>

project>

generatorConfig.xml配置文件





<generatorConfiguration>
    
    
    <classPathEntry location="C:\mybatisMaven\lib\mysql-connector-java-5.1.7-bin.jar"/>
    
    <context id="testTables" targetRuntime="MyBatis3">

        <commentGenerator>
            
            <property name="suppressAllComments" value="true" />
            
            <property name="suppressDate" value="true" />
        commentGenerator>
        
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/scm?useUnicode=true&characterEncoding=UTF-8" userId="root" password="root">
        jdbcConnection>

        
        <javaModelGenerator targetPackage="zhongfucheng.entity"
                            targetProject="src/main/java">
            
            <property name="trimStrings" value="false" />
        javaModelGenerator>
        
        <sqlMapGenerator targetPackage="zhongfucheng.dao"
                         targetProject="src/main/java" />
        
        <javaClientGenerator type="XMLMAPPER" targetPackage="zhongfucheng.dao" targetProject="src/main/java" />

        <table tableName="account" domainObjectName="Account"/>
        <table tableName="supplier" domainObjectName="Supplier"/>
    context>
generatorConfiguration>

使用插件步骤

Mybatis第九篇【基于Maven在Idea下Mybatis逆向工程】_第1张图片

最后生成代码

如果对我们上面generatorConfig.xml配置的包信息不清楚的话,那么可以看一下我们的完整项目结构图…

因为我们在Idea下是不用写对应的工程名字的,而在eclipse是有工程名字的。

Mybatis第九篇【基于Maven在Idea下Mybatis逆向工程】_第2张图片

你可能感兴趣的:(Mybatis,Mybatis)