• idea集成 MyBatis Generator 插件,自动生成dao,model,sql map文件


    1.集成到开发环境中

    以maven管理的功能来举例,只需要将插件添加到pom.xml文件中即可。(注意此处是以plugin的方式,放在<plugins></plugins>中间即可)

    <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.2</version>
    </plugin>
    

      

    2.编写配置文件 generatorConfig.xml

    注意:在idea开发环境下,此文件需要放在resource根目录下,mybatis generator默认加载此目录的配置文件

    <?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>
        <!--数据库驱动jar -->
        <classPathEntry
            location="D:.m2
    epositorymysqlmysql-connector-java5.1.33mysql-connector-java-5.1.33.jar" />
    
        <context id="Tables" targetRuntime="MyBatis3">
            <!--去除注释 -->
            <commentGenerator>
                <property name="suppressAllComments" value="true" />
            </commentGenerator>
    
            <!--数据库连接 -->
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                connectionURL="jdbc:mysql://129.1.18.18:3306/ssm_demo" userId="root"
                password="root">
            </jdbcConnection>
            <!--默认false Java type resolver will always use java.math.BigDecimal if 
                the database column is of type DECIMAL or NUMERIC. -->
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false" />
            </javaTypeResolver>
    
            <!--生成实体类 指定包名 以及生成的地址 (可以自定义地址,但是路径不存在不会自动创建 使用Maven生成在target目录下,会自动创建) -->
            <javaModelGenerator targetPackage="model"
                targetProject="F:lhlssmsrcmainjava">
                <property name="enableSubPackages" value="true" />
                <property name="trimStrings" value="true" />
            </javaModelGenerator>
            <!--生成SQLMAP文件 -->
            <sqlMapGenerator targetPackage="mapper"
                targetProject="F:lhlssmsrcmain
    esources">
                <property name="enableSubPackages" value="false" />
            </sqlMapGenerator>
            <!--生成Dao文件 可以配置 type="XMLMAPPER"生成xml的dao实现 context id="DB2Tables" 修改targetRuntime="MyBatis3" -->
            <javaClientGenerator type="XMLMAPPER"
                targetPackage="dao"
                targetProject="F:lhlssmsrcmainjava">
                <property name="enableSubPackages" value="false" />
            </javaClientGenerator>
    
            <!--对应数据库表 mysql可以加入主键自增 字段命名 忽略某字段等 -->
            <table tableName="user_test" domainObjectName="UserTest"
                enableCountByExample="false" enableUpdateByExample="false"
                enableDeleteByExample="false" enableSelectByExample="false"
                selectByExampleQueryId="false" />
        </context>
    </generatorConfiguration>
    

      

    最后只需在plugins中找到mybatis-generator plugin即可,双击运行或右击 运行都可。

  • 相关阅读:
    实现停车记录
    Python第四章__装饰器、迭代器
    请问使用jmeter在tcp取样器测试中服务器名称或ip,端口可以填变量值吗?
    [drp 7]转发和重定向的区别
    [drp 6]接口和抽象类的区别,及其应用场景
    MongoDB 3: 使用中的问题,及其应用场景
    MongoDB 2: 安装和使用
    MongoDB 1: NoSQL 和 SQL的区别
    Redis 2:简单使用
    Redis 1:简介
  • 原文地址:https://www.cnblogs.com/itzyz/p/10954445.html
Copyright © 2020-2023  润新知