zoukankan      html  css  js  c++  java
  • mybatis-generator的使用

    mybatis-generator的主要作用:

      根据表自动生成bean、dao、mapper.xml(就是自动生成底层的数据库)

    1.添加依赖

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

    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">
    <!-- mybatis-generator的核心配置文件 -->
    <generatorConfiguration>
      <classPathEntry location="/Users/lichunyu/springboot/repository/mysql/mysql-connector-java/5.1.45/mysql-connector-java-5.1.45.jar" />
    
      <context id="DB2Tables" targetRuntime="MyBatis3">
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://127.0.0.1:3306/poll2.0"
            userId="root"
            password="root">
        </jdbcConnection>
    
        <!--指定生成的类型为java类型,避免数据库中number等类型字段 -->
        <javaTypeResolver >
          <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>
    
        <!--自动生成的实体的存放包路径 -->
        <javaModelGenerator targetPackage="com.briup.apps.poll.bean" targetProject="./src/main/java">
          <property name="enableSubPackages" value="true" />
          <property name="trimStrings" value="true" />
        </javaModelGenerator>
    
        <!--自动生成的*Mapper.xml文件存放路径 -->
        <sqlMapGenerator targetPackage="mapper"  targetProject="./src/main/resources">
          <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>
    
        <!--自动生成的*Mapper.java存放路径 -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.briup.apps.poll.dao"  targetProject="./src/main/java">
          <property name="enableSubPackages" value="true" />
        </javaClientGenerator>
    
        <!-- 映射配置 -->
         
        <table tableName="poll_survy" domainObjectName="Survy" ></table>
        <!--
        <table tableName="poll_school" domainObjectName="School" ></table>
        <table tableName="poll_grade" domainObjectName="Grade" ></table>
        <table tableName="poll_clazz" domainObjectName="Clazz" ></table>
        <table tableName="poll_course" domainObjectName="Course" ></table>
        <table tableName="poll_grade_course" domainObjectName="GradeCourse" ></table>
        <table tableName="poll_user" domainObjectName="User" ></table>
        <table tableName="poll_option" domainObjectName="Option" ></table>
        <table tableName="poll_question" domainObjectName="Question" ></table>
        <table tableName="poll_questionnaire" domainObjectName="Questionnaire" ></table>
        <table tableName="poll_questionnaire_question" domainObjectName="QuestionnaireQuestion" ></table>
        -->
      </context>
    </generatorConfiguration>

    3.开始工作(记得关闭项目)

     mvn -Dmybatis.generator.overwrite=true mybatis-generator:generate
  • 相关阅读:
    iOS开发Quzrtz2D 十:圆形图片的绘制以及加边框圆形图片的绘制
    团队项目(周日站立会议)
    团队项目(周六站立会议)
    团队项目(spring会议)
    团队项目(第一次会议)
    结对开发项目 电梯调度发布版(已完成) 刘佳琪、兰梦
    结对测试二(求二维数组的子数组之和最大值)(兰梦、刘佳琪)
    敏捷开发(对于敏捷开发模式的理解)
    上课结对测试项目(求整数数组的子数组之和的最大值)(兰梦,刘佳琪)
    结对开发项目:多部电梯调度(一)(兰梦、刘佳琪)
  • 原文地址:https://www.cnblogs.com/zzuli/p/9226131.html
Copyright © 2011-2022 走看看