MyBatis——Generator

1、依赖:

<!--mybatis逆向工程-->
<dependency>
  <groupId>org.mybatis.generator</groupId>
  <artifactId>mybatis-generator-core</artifactId>
  <version>1.3.7</version>
</dependency>
  <plugins>
    <plugin>
      <groupId>org.mybatis.generator</groupId>
      <artifactId>mybatis-generator-maven-plugin</artifactId>
      <version>1.3.7</version>
      <configuration>
        <!--配置文件的路径:可以指定-->
        <!--<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>-->
        <verbose>true</verbose>
        <overwrite>true</overwrite>
      </configuration>
    </plugin>
  </plugins>

2、配置文件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>
                <!--指定了驱动jar包的位置,这个是针对下载Jar包的方式,因为用了maven所以这个就用不上了-->
                <classPathEntry location="E:\MavenLib\mysql\mysql-connector-java\5.1.6\mysql-connector-java-5.1.6.jar" />
            
                <context id="DB2Tables" targetRuntime="MyBatis3">
                    <commentGenerator>
                        <property name="suppressDate" value="false"/>
                        <!-- 是否去除自动生成的注释 true:是 : false:否 -->
                        <property name="suppressAllComments" value="true"/>
                    </commentGenerator>
            
                    <!--jdbc的数据库连接-->
                    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                                    connectionURL="jdbc:mysql://localhost:3306/store?characterEncoding=utf-8"
                                    userId="root"
                                    password="000000">
                        <!--<property name="serverTimezone" value="UTC"/>-->
                        <property name="nullCatalogMeansCurrent" value="true"/>
                    </jdbcConnection>
            
                    <!--非必须,类型处理器,在数据库类型和java类型之间的转换控制-->
                    <javaTypeResolver>
                        <!-- 默认情况下数据库中的 decimal,bigInt 在 Java 对应是 sql 下的 BigDecimal 类 -->
                        <!-- 不是 double 和 long 类型 -->
                        <!-- 使用常用的基本类型代替 sql 包下的引用类型 -->
                        <property name="forceBigDecimals" value="false" />
                    </javaTypeResolver>
            
            
                    <!--指定生成entity实体类的具体位置-->
                    <javaModelGenerator targetPackage="com.qf.domain" targetProject="./src/main/java">
                        <property name="enableSubPackages" value="true"/>
                        <property name="trimStrings" value="true"/>
                    </javaModelGenerator>
                    <!--指定生成mybatis映射xml文件的包名和位置-->
                    <sqlMapGenerator targetPackage="mapper" targetProject="./src/main/resources">
                        <property name="enableSubPackages" value="true"/>
                    </sqlMapGenerator>
                    <!--指定生成mapper接口的具体位置-->
                    <javaClientGenerator targetPackage="com.qf.dao" targetProject="./src/main/java" type="XMLMAPPER">
                        <property name="enableSubPackages" value="true"/>
                    </javaClientGenerator>
            
                    <!--&lt;!&ndash; 要生成entity/mapper的表名及自定义的DO名 &ndash;&gt;-->
                    <!--<table tableName="users" domainObjectName="User"/>-->
            
                    <!--<table tableName="product_brand" domainObjectName="ProductBrand" />-->
            
                    <!--mybatis generator代码生成器在默认的情况下会生成对于表实体类的一个Examle类, 可以更改生成器的配置可避免生成Examle类,
                    enableCountByExample,enableUpdateByExample,enableDeleteByExample,enableSelectByExample等配置为false后, 就不会生成生成Examle类了 -->
            
                    <table tableName="t_business" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
            
                </context>
            </generatorConfiguration>

3、运行:

mvn mybatis-generator:generate

 

转载于:https://www.cnblogs.com/Tractors/p/11317328.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值