最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MyBatis Generator的簡單使用方法示例

 更新時(shí)間:2021年02月12日 10:08:05   作者:轉(zhuǎn)行當(dāng)司機(jī)  
這篇文章主要給大家介紹了關(guān)于MyBatis Generator的簡單使用方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

添加配置文件

在項(xiàng)目resource目錄下創(chuàng)建mybatis-generator文件夾

創(chuàng)建文件夾

在文件夾下創(chuàng)建generatorConfig.xml,配置需要生成代碼的數(shù)據(jù)表

<?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>
 <properties resource="mybatis-generator/generator.properties"/>
 <!-- 連接數(shù)據(jù)庫jar包的路徑-->
 <!--<classPathEntry location="d:/java/JavaTools/mysql-connector-java-5.1.48/mysql-connector-java-5.1.48-bin.jar"/>-->
 <context id="DB2Tables" targetRuntime="MyBatis3">
  <commentGenerator>
   <property name="suppressDate" value="true"/>
   <!-- 是否去除自動生成的注釋 true:是 : false:否 -->
   <property name="suppressAllComments" value="true"/>
  </commentGenerator>

  <!--數(shù)據(jù)庫連接參數(shù) -->
  <jdbcConnection
    driverClass="${driverClassName}"
    connectionURL="${url}"
    userId="${username}"
    password="${password}">
  </jdbcConnection>

  <javaTypeResolver>
   <property name="forceBigDecimals" value="false"/>
  </javaTypeResolver>

  <!-- 實(shí)體類的包名和存放路徑 -->
  <javaModelGenerator targetPackage="com.shop.order.bean" targetProject="src/main/java">
   <property name="enableSubPackages" value="true"/>
   <property name="trimStrings" value="true"/>
  </javaModelGenerator>

  <!-- 生成映射文件*.xml的位置-->
  <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
   <property name="enableSubPackages" value="true"/>
  </sqlMapGenerator>

  <!-- 生成DAO的包名和位置 -->
  <javaClientGenerator type="XMLMAPPER" targetPackage="com.shop.order.mapper" targetProject="src/main/java">
   <property name="enableSubPackages" value="true"/>
  </javaClientGenerator>

  <!-- tableName:數(shù)據(jù)庫中的表名或視圖名;domainObjectName:生成的實(shí)體類的類名-->
  <table tableName="book" domainObjectName="Book"
    enableCountByExample="false"
    enableUpdateByExample="false"
    enableDeleteByExample="false"
    enableSelectByExample="false"
    selectByExampleQueryId="false"/>
  <!-- 可以添加多個(gè)需要生產(chǎn)代碼的實(shí)體-->
  <!--
    <table tableName="xxx" domainObjectName="xxx"
      enableCountByExample="false"
      enableUpdateByExample="false"
      enableDeleteByExample="false"
      enableSelectByExample="false"
      selectByExampleQueryId="false"/>
    ...
    <table tableName="xxx" domainObjectName="xxx"
      enableCountByExample="false"
      enableUpdateByExample="false"
      enableDeleteByExample="false"
      enableSelectByExample="false"
      selectByExampleQueryId="false"/>
  -->
 </context>
</generatorConfiguration>

在文件夾下創(chuàng)建generator.properties配置文件

driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/store?useUnicode=true&characterEncoding=UTF-8&relaxAutoCommit=true&zeroDateTimeBehavior=convertToNull
username=root
password=root

配置Maven

pom.xml中引入依賴

<build>
    <plugins>
      <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.5</version>
        <configuration>
          <configurationFile>src/main/resources/mybatis-generator/generatorConfig.xml</configurationFile>
          <verbose>true</verbose>
          <overwrite>true</overwrite>
        </configuration>
        <executions>
          <execution>
            <id>Generate MyBatis Artifacts</id>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.5</version>
          </dependency>
          <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.30</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

執(zhí)行Maven插件

雙擊運(yùn)行mybatis-generator:generate

在這里插入圖片描述

控制臺輸出結(jié)果,生產(chǎn)mapper和bean文件

在這里插入圖片描述

總結(jié)

到此這篇關(guān)于MyBatis Generator簡單使用方法的文章就介紹到這了,更多相關(guān)MyBatis Generator使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

合川市| 禄丰县| 石楼县| 内江市| 定西市| 始兴县| 阜宁县| 那坡县| 布尔津县| 建水县| 寻乌县| 武汉市| 衡阳市| 南昌县| 兴宁市| 安达市| 巩留县| 元阳县| 太原市| 临颍县| 泽库县| 金湖县| 婺源县| 阳高县| 方山县| 嘉义市| 利川市| 富源县| 青海省| 齐河县| 金昌市| 安乡县| 开鲁县| 广饶县| 万全县| 大埔区| 德阳市| 镇雄县| 蛟河市| 永新县| 定襄县|