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
  • 相关阅读:
    Lock接口、AbstractQueuedSynchronizer队列同步器、重入锁、读写锁
    SpringMVC一点简单地源码解析
    MyBatis源码部分简单地解析
    笔记本外接显示器不显示
    WPF查找指定类型的父/子控件
    java.io.EOFException: HttpConnectionOverHTTP
    Spark读取HDFS某个路径下的子文件夹中的所有文件
    utf-8 BOM前导3个字节头
    org.apache.hadoop.yarn.exceptions.InvalidAuxServiceException: The auxService:spark_shuffle does not exist
    org.apache.spark.sql.AnalysisException: Table or view not found解决办法
  • 原文地址:https://www.cnblogs.com/zzuli/p/9226131.html
Copyright © 2011-2022 走看看