欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MyBatis Generator的簡(jiǎn)單使用方法示例

 更新時(shí)間:2021年02月12日 10:08:05   作者:轉(zhuǎn)行當(dāng)司機(jī)  
這篇文章主要給大家介紹了關(guān)于MyBatis Generator的簡(jiǎn)單使用方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(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"/>
   <!-- 是否去除自動(dòng)生成的注釋 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

在這里插入圖片描述

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

在這里插入圖片描述

總結(jié)

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

相關(guān)文章

  • spring boot和mybatis集成分頁插件

    spring boot和mybatis集成分頁插件

    這篇文章主要為大家詳細(xì)介紹了spring boot和mybatis集成分頁插件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • executor包執(zhí)行器功能

    executor包執(zhí)行器功能

    這篇文章主要介紹了executor包執(zhí)行器功能,executor包中的各個(gè)子包提供的功能,最終這些功能都由Executor接口及其實(shí)現(xiàn)類共同對(duì)外提供服務(wù)。下文介紹該執(zhí)行功能,具有一定的參考價(jià)值,需要的朋友可以考一下
    2022-02-02
  • mybatis攔截器注冊(cè)初始化編寫示例及如何生效詳解

    mybatis攔截器注冊(cè)初始化編寫示例及如何生效詳解

    這篇文章主要為大家介紹了mybatis攔截器注冊(cè)初始化編寫示例及如何生效詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08
  • Spring?Boot?+?EasyExcel?+?SqlServer?進(jìn)行批量處理數(shù)據(jù)的高效方法

    Spring?Boot?+?EasyExcel?+?SqlServer?進(jìn)行批量處理數(shù)據(jù)的高效方法

    在日常開發(fā)和工作中,我們可能要根據(jù)用戶上傳的文件做一系列的處理,本篇文章就以Excel表格文件為例,主要介紹了Spring?Boot?+?EasyExcel?+?SqlServer?進(jìn)行批量處理數(shù)據(jù)的高效方法,需要的朋友可以參考下
    2024-06-06
  • java實(shí)現(xiàn)飛機(jī)大戰(zhàn)游戲

    java實(shí)現(xiàn)飛機(jī)大戰(zhàn)游戲

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)飛機(jī)大戰(zhàn)游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-03-03
  • 使用Java實(shí)現(xiàn)5種負(fù)載均衡算法實(shí)例

    使用Java實(shí)現(xiàn)5種負(fù)載均衡算法實(shí)例

    負(fù)載均衡指由多臺(tái)服務(wù)器以對(duì)稱的方式組成一個(gè)服務(wù)器集合,每臺(tái)服務(wù)器都具有等價(jià)的地位,都可以單獨(dú)對(duì)外提供服務(wù)而無須其他服務(wù)器的輔助,這篇文章主要給大家介紹了關(guān)于使用Java實(shí)現(xiàn)5種負(fù)載均衡算法的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • Java?Mybatis框架由淺入深全解析下篇

    Java?Mybatis框架由淺入深全解析下篇

    MyBatis是一個(gè)優(yōu)秀的持久層框架,它對(duì)jdbc的操作數(shù)據(jù)庫的過程進(jìn)行封裝,使開發(fā)者只需要關(guān)注SQL本身,而不需要花費(fèi)精力去處理例如注冊(cè)驅(qū)動(dòng)、創(chuàng)建connection、創(chuàng)建statement、手動(dòng)設(shè)置參數(shù)、結(jié)果集檢索等jdbc繁雜的過程代碼,本文將作為最終篇為大家介紹MyBatis的使用
    2022-07-07
  • Mybatis條件if test如何使用枚舉值

    Mybatis條件if test如何使用枚舉值

    這篇文章主要介紹了Mybatis條件if test如何使用枚舉值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • Struts2 $,#,%詳解及實(shí)例代碼

    Struts2 $,#,%詳解及實(shí)例代碼

    這篇文章主要介紹了Struts2 $,#,%詳解及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • Java由淺入深細(xì)數(shù)數(shù)組的操作上

    Java由淺入深細(xì)數(shù)數(shù)組的操作上

    數(shù)組對(duì)于每一門編程語言來說都是重要的數(shù)據(jù)結(jié)構(gòu)之一,當(dāng)然不同語言對(duì)數(shù)組的實(shí)現(xiàn)及處理也不盡相同。Java?語言中提供的數(shù)組是用來存儲(chǔ)固定大小的同類型元素
    2022-04-04

最新評(píng)論