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


    前言

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

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

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

    修改pom.xml文件

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

    
    <?xml version="1.0" encoding="UTF-8"?>
    <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.0</modelVersion>
    
        <groupId>asdf</groupId>
        <artifactId>asdf</artifactId>
        <version>1.0-SNAPSHOT</version>
        <build>
            <finalName>zhongfucheng</finalName>
            <plugins>
                <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.2</version>
                    <configuration>
                        <verbose>true</verbose>
                        <overwrite>true</overwrite>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    </project>

    generatorConfig.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>
        <!--
            <properties resource="conn.properties" />
              -->
        <!-- 处理1,这里的jar包位置可能需要修改 -->
        <classPathEntry location="C:mybatisMavenlibmysql-connector-java-5.1.7-bin.jar"/>
        <!-- 指定运行环境是mybatis3的版本 -->
        <context id="testTables" targetRuntime="MyBatis3">
    
            <commentGenerator>
                <!-- 是否取消注释 -->
                <property name="suppressAllComments" value="true" />
                <!-- 是否生成注释代时间戳 -->
                <property name="suppressDate" value="true" />
            </commentGenerator>
            <!-- 处理2   jdbc 连接信息,看看库是否存在 -->
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                            connectionURL="jdbc:mysql://localhost:3306/scm?useUnicode=true&amp;characterEncoding=UTF-8" userId="root" password="root">
            </jdbcConnection>
    
            <!--处理3   targetPackage指定模型在生成在哪个包 ,targetProject指定项目的src,-->
            <javaModelGenerator targetPackage="zhongfucheng.entity"
                                targetProject="src/main/java">
                <!-- 去除字段前后空格 -->
                <property name="trimStrings" value="false" />
            </javaModelGenerator>
            <!--处理4   配置SQL映射文件生成信息 -->
            <sqlMapGenerator targetPackage="zhongfucheng.dao"
                             targetProject="src/main/java" />
            <!-- 处理5   配置dao接口生成信息-->
            <javaClientGenerator type="XMLMAPPER" targetPackage="zhongfucheng.dao" targetProject="src/main/java" />
    
            <table tableName="account" domainObjectName="Account"/>
            <table tableName="supplier" domainObjectName="Supplier"/>
        </context>
    </generatorConfiguration>

    使用插件步骤

    这里写图片描述

    最后生成代码

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

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

    这里写图片描述

  • 相关阅读:
    颜色代码 #000~#FFF & DML案例设计
    SQLScript DML 创建 & 查询 & 序列(条件查询 日起查询 关联查询 子查询 分组查询 查询内容拼接 模糊查询)
    Java JDBC 连接数据库 Demo
    document的JavaScript一些用法
    dxSpreadSheet的报表demo-关于设计报表模板问题
    dxSpreadSheet的报表demo-关于设计报表模板的Datagroup问题
    TJSON的烦人的泄漏
    dxSpreadSheet的报表
    TDXSpreadSheet中自定义公式函数三大步骤
    SVN项目监视器的配置文件
  • 原文地址:https://www.cnblogs.com/zhong-fucheng/p/7554348.html
Copyright © 2020-2023  润新知