• idea中使用MyBatis Generator


    1.新建maven项目

    2.新建Generator配置文件 generator_config.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>
        <!--mysql 连接数据库jar 这里选择自己本地位置-->
        <classPathEntry location="E:
    epositorymysqlmysql-connector-java5.1.18mysql-connector-java-5.1.18.jar" />
        <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/demo"
                            userId="root"
                            password="11402">
            </jdbcConnection>
           
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false" />
            </javaTypeResolver>
    
            <!-- 生成entity的包名和位置 -->
            <javaModelGenerator targetPackage="com.example.entity"
                                targetProject="src/main/java">
                <!-- enableSubPackages:是否让schema作为包的后缀 -->
                <property name="enableSubPackages" value="false" />
                <!-- 从数据库返回的值被清理前后的空格 -->
                <property name="trimStrings" value="true" />
            </javaModelGenerator>
    
            <!-- 生成mappr的包名和位置-->
            <sqlMapGenerator targetPackage="main.resources.mapping"
                             targetProject="src">
                <!-- enableSubPackages:是否让schema作为包的后缀 -->
                <property name="enableSubPackages" value="false" />
            </sqlMapGenerator>
    
            <!-- 生成DAO的包名和位置-->
            <javaClientGenerator type="XMLMAPPER"
                                 targetPackage="com.example.dao"
                                 targetProject="src/main/java">
                <!-- enableSubPackages:是否让schema作为包的后缀 -->
                <property name="enableSubPackages" value="false" />
            </javaClientGenerator>
    
            <!--  tableName是数据库中的表名或视图名 domainObjectName是
          entity名-->
            <table tableName="t_test" domainObjectName="Test"
                   enableCountByExample="false" enableUpdateByExample="false"
                   enableDeleteByExample="false" enableSelectByExample="false"
                   selectByExampleQueryId="false"></table>
        </context>
    </generatorConfiguration>

    3.pom文件插入配置

    <plugin>
          <groupId>org.mybatis.generator</groupId>
          <artifactId>mybatis-generator-maven-plugin</artifactId>
          <version>1.3.2</version>
    
          <configuration>
            <!--配置文件的位置-->
            <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
            <overwrite>true</overwrite>
            <verbose>true</verbose>
          </configuration>
        </plugin>

    4.配置config 

    mybatis-generator:generate -e

    5.run

  • 相关阅读:
    nexus3.x Liunx私库安装教程 (亲测有用)
    nexus 3.x下载 3.18.1(maven 私服)
    halo项目源码本地部署解决方案
    gradle的安装配置
    raw.githubusercontent.com 访问不了
    springboot使用quartz解决调用不到spring注入service的问题
    Linux在不能使用yum的环境下安装pgsql(公司内网)
    idea 里面的maven依赖下载不了,以及mabtis依赖包错误
    关于oracle 数据库效率的优化
    关于oracle 不常用的job 运行时间设置
  • 原文地址:https://www.cnblogs.com/ztfcb/p/9957777.html
Copyright © 2020-2023  润新知