idea版(ssm)Mybatis逆向工程,2种启动方法

(1)idea版的mybatis逆向工程,👉Maven配置启动

【1】坐标pom

其中核心坐标

   <dependencies>
    <!--(7)用于整合Mybatis的坐标 -->
    <!-- mybatis坐标 -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.4.5</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <!-- mybatis-generator自动生成代码插件 -->
      <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.6</version>
        <dependencies>
          <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

【2】resources

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>
    <context id="MysqlContext" defaultModelType="flat">
        <property name="beginningDelimiter" value="`"/>
        <property name="endingDelimiter" value="`"/>
   <!-- (0)model中数据属性的修改-->
        <!--【1】plugin中修改-->
        <!--{1}在model中添加HashCode(现在我不用)-->
<!--        <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"/>-->
        <!--{2}在model中添加自动生成序列化(现在我不用)-->
<!--        <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />-->
        <!--{3}在model中添加toString-->
        <plugin type="org.mybatis.generator.plugins.ToStringPlugin" />

        <!--【2】commentGenerator中的修改
               注意:1property: value="true”表示改标签的效果关闭-->
        <commentGenerator>
            <!--{1}是否去除自动生成的注释(关闭)  -->
            <property name="suppressAllComments" value="true" />
            <!--{2}阻止注释中包含时间戳(关闭)-->
            <property name="suppressDate" value="true" />
            <!--{3}注释是否包含数据库表的注释信息-->
            <property name="addRemarkComments" value="false" />
        </commentGenerator>

        <!--  不生成注释  -->
        <!--(1)配置数据库驱动、所选择数据库、用户名密码等信息  -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://127.0.0.1/xk_spring_mybatis?serverTimezone=CTT&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;allowMultiQueries=true"
                        userId="账号"
                        password="密码">
        </jdbcConnection>
        <!-- (2)是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.)  -->
        <javaTypeResolver>
            <property name="forceBigDecimals" value=" false"/>
        </javaTypeResolver>

        <!-- (3)实体类生成的地方  -->
        <!--  是否在当前路径下新加一层  -->
        <!--  是否针对string类型的字段在set的时候进行trim调用  -->
        <javaModelGenerator targetPackage="model" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!-- (4)映像Mapper.xml生成的地方  -->
        <!--  是否在当前路径下新加一层  -->
        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>

        <!--  (5)dao/mapper生成的地方  -->
        <!--  是否在当前路径下新加一层  -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="dao" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <!--  (6)根据数据库的表和生成>>>java中的实体名  -->
        <table tableName="user_test01"
               domainObjectName="User_test01"
               enableCountByExample="false"
               enableUpdateByExample="false"
               enableDeleteByExample="false"
               enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>

    </context>

</generatorConfiguration>

【3】启动

{1}Maven的生命周期

{2}Maven的配置启动

 项目指令:

mybatis-generator:generate -e

【4】运行结果

 

总结:

1我也是找了网上很多的mybatis的配置,找到了这种用Maven配置启动是比较简单的,相对于用java类启动容易很懂。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值