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

SpringBoot整合mybatis-generator插件流程詳細(xì)講解

 更新時(shí)間:2023年02月03日 10:19:38   作者:TryMyBestTo  
這篇文章主要介紹了SpringBoot整合mybatis-generator插件流程,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧

mybatis-generator 插件

mybatis 相關(guān)依賴(lài)

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>3.0.1</version>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.25</version>
</dependency>
<!-- 數(shù)據(jù)庫(kù)連接池 -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.2.15</version>
</dependency>

mybatis-generator 插件,自動(dòng)生成mybatis所需要的 dao、bean、mapper.xml文件。

<build>
    <plugins>
        <!-- mybatis 插件 -->
        <plugin>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <version>1.3.7</version>
            <configuration>
                <verbose>true</verbose>
                <overwrite>true</overwrite>
            </configuration>
        </plugin>
    </plugins>
</build>

創(chuàng)建generatorConfig.xml 文件,是這個(gè)插件的配置文件

需要第八行<classPathEntry location=“項(xiàng)目mysql-connection-java-版本.jar 包的絕對(duì)路徑”

<?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="application.properties"/>
  <!-- mysql驅(qū)動(dòng)的位置 這個(gè)是MySQL連接的jar包,你需要指定你自己計(jì)算機(jī)上的jar包的位置-->
  <classPathEntry location="E:\Java\IDEA\code\mall\src\main\resources\lib\mysql-connector-java-8.0.25.jar" />
  <context id="MysqlTables" targetRuntime="MyBatis3">
    <property name="autoDelimitKeywords" value="true"/>
    <!--可以使用``包括字段名,避免字段名與sql保留字沖突報(bào)錯(cuò)-->
    <property name="beginningDelimiter" value="`"/>
    <property name="endingDelimiter" value="`"/>
    <!-- 是否生成注釋 -->
    <commentGenerator>
      <!-- 是否生成注釋代時(shí)間戳 -->
      <property name="suppressDate" value="true"/>
      <!-- 是否去除自動(dòng)生成的注釋 true:是 : false:否 -->
      <property name="suppressAllComments" value="true"/>
    </commentGenerator>
    <!--數(shù)據(jù)庫(kù)鏈接地址賬號(hào)密碼-->
    <jdbcConnection driverClass="${spring.datasource.driver-class-name}"
      connectionURL="${spring.datasource.url}"
      userId="${spring.datasource.username}"
      password="${spring.datasource.password}">
      <property name="nullCatalogMeansCurrent" value="true"/>
    </jdbcConnection>
    <!-- 非必需,類(lèi)型處理器,在數(shù)據(jù)庫(kù)類(lèi)型和java類(lèi)型之間的轉(zhuǎn)換控制-->
    <!-- 默認(rèn)false,把JDBC DECIMAL 和 NUMERIC 類(lèi)型解析為 Integer,為 true時(shí)把JDBC DECIMAL 和
         NUMERIC 類(lèi)型解析為java.math.BigDecimal -->
    <javaTypeResolver>
      <!-- 是否使用bigDecimal, false可自動(dòng)轉(zhuǎn)化以下類(lèi)型(Long, Integer, Short, etc.) -->
      <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>
    <!-- 生成實(shí)體類(lèi)地址 這里需要你改動(dòng),其中 targetPackage 需要根據(jù)你自己創(chuàng)建的目錄進(jìn)行改動(dòng) -->
    <javaModelGenerator targetPackage="${generator.javaModel-targetPackage}"
      targetProject="src/main/java">
      <!-- 是否允許子包,即targetPackage.schemaName.tableName -->
      <property name="enableSubPackages" value="true"/>
      <!-- 是否對(duì)類(lèi)CHAR類(lèi)型的列的數(shù)據(jù)進(jìn)行trim操作 -->
      <property name="trimStrings" value="true"/>
      <!-- 建立的Model對(duì)象是否 不可改變  即生成的Model對(duì)象不會(huì)有 setter方法,只有構(gòu)造方法 -->
      <property name="immutable" value="true"/>
    </javaModelGenerator>
    <!--生成mapper映射文件存放位置-->
    <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
      <property name="enableSubPackages" value="true"/>
    </sqlMapGenerator>
    <!--生成Dao類(lèi)存放位置-->
    <javaClientGenerator type="XMLMAPPER" targetPackage="${generator.mappers}"
      targetProject="src/main/java">
      <property name="enableSubPackages" value="true"/>
    </javaClientGenerator>
    <!--生成對(duì)應(yīng)表及類(lèi)名-->
    <!-- schema即為數(shù)據(jù)庫(kù)名 tableName為對(duì)應(yīng)的數(shù)據(jù)庫(kù)表 domainObjectName是要生成的實(shí)體類(lèi) enable*ByExample 是否生成 example類(lèi) -->
    <table schema="root" tableName="imooc_mall_cart" domainObjectName="Cart"
      enableCountByExample="false"
      enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
      selectByExampleQueryId="false">
    </table>
    <table tableName="imooc_mall_category" domainObjectName="Category" enableCountByExample="false"
      enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
      selectByExampleQueryId="false">
    </table>
    <table tableName="imooc_mall_order" domainObjectName="Order" enableCountByExample="false"
      enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
      selectByExampleQueryId="false">
    </table>
    <table tableName="imooc_mall_order_item" domainObjectName="OrderItem"
      enableCountByExample="false"
      enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
      selectByExampleQueryId="false">
    </table>
    <table tableName="imooc_mall_product" domainObjectName="Product" enableCountByExample="false"
      enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
      selectByExampleQueryId="false">
    </table>
    <table tableName="imooc_mall_user" domainObjectName="User" enableCountByExample="false"
      enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
      selectByExampleQueryId="false">
    </table>
  </context>
</generatorConfiguration>

然后修改 application.properties 文件,增加一點(diǎn)配置項(xiàng)。

當(dāng)然,也可以選擇直接在 generatorConfig.xml 文件中書(shū)寫(xiě),但想要運(yùn)行整個(gè)項(xiàng)目,也是必須配置mysql的。

#mysql配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useSSL=false&characterEncoding=utf8&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=123456
#mybatis
#指定mapper.xml文件的位置
mybatis.mapper-locations=classpath:mapper/*.xml
#設(shè)置pojo類(lèi)型別名
mybatis.type-aliases-package=com.daxiong.mall.pojo
#Generator配置
#生成pojo位置
generator.javaModel-targetPackage=com.daxiong.mall.pojo
#生成接口位置
generator.mappers=com.daxiong.mall.mapper

啟動(dòng)插件生成文件:打開(kāi)maven工具欄-》選擇當(dāng)前項(xiàng)目名-》Plugins-》mybatis-generator -》雙擊運(yùn)行 mybatis-generator:generate 。

此時(shí),便會(huì)**自動(dòng)生成**mybatis所需要的 dao、bean、mapper.xml文件

自動(dòng)生成的mapper接口示例:

// 根據(jù) 主索引字段 刪除
int deleteByPrimaryKey(Integer id);
// 插入
int insert(Order record);
// 可選擇性插入(值為null的字段不插入,使用默認(rèn)值)
int insertSelective(Order record);
// 根據(jù) 主索引字段 查詢(xún)
Order selectByPrimaryKey(Integer id);
// 可選擇性更新(值為null的字段不插入,使用默認(rèn)值)
int updateByPrimaryKeySelective(Order record);
// 更新
int updateByPrimaryKey(Order record);

通知MyBatis,mapper接口存放的位置:

方法一:為 主啟動(dòng)類(lèi)添加注解:

@MapperScan(basePackages = “com.daxiong.mall.mapper”):告訴 ,mapper 接口放在了哪里。

方法二:為為每個(gè) mapper 接口添加注解:

@Mapper:讓此接口在Spring Ioc 初始化時(shí)生成 bean,以便其他類(lèi)注入使用。

到此這篇關(guān)于SpringBoot整合mybatis-generator插件流程詳細(xì)講解的文章就介紹到這了,更多相關(guān)SpringBoot整合mybatis-generator內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 44條Java代碼優(yōu)化建議

    44條Java代碼優(yōu)化建議

    代碼優(yōu)化的最重要的作用應(yīng)該是:避免未知的錯(cuò)誤。因此,在寫(xiě)代碼的時(shí)候,從源頭開(kāi)始注意各種細(xì)節(jié),權(quán)衡并使用最優(yōu)的選擇,將會(huì)很大程度上避免出現(xiàn)未知的錯(cuò)誤,從長(zhǎng)遠(yuǎn)看也極大的降低了工作量
    2018-03-03
  • Java學(xué)習(xí)教程之定時(shí)任務(wù)全家桶

    Java學(xué)習(xí)教程之定時(shí)任務(wù)全家桶

    這篇文章主要給大家介紹了關(guān)于Java學(xué)習(xí)教程之定時(shí)任務(wù)全家桶的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • Java使用JNA調(diào)用DLL文件

    Java使用JNA調(diào)用DLL文件

    JNA(Java?Native?Access)是一個(gè)在?Java?中調(diào)用本地代碼的開(kāi)源框架,提供了一種簡(jiǎn)單、高效的方式來(lái)訪(fǎng)問(wèn)本地動(dòng)態(tài)鏈接庫(kù),下面我們來(lái)看看Java如何使用JNA調(diào)用DLL文件吧
    2024-12-12
  • Mybatis一對(duì)多和多對(duì)一處理的深入講解

    Mybatis一對(duì)多和多對(duì)一處理的深入講解

    Mybatis可以通過(guò)關(guān)聯(lián)查詢(xún)實(shí)現(xiàn),關(guān)聯(lián)查詢(xún)是幾個(gè)表聯(lián)合查詢(xún),只查詢(xún)一次,通過(guò)在resultMap里面的association,collection節(jié)點(diǎn)配置一對(duì)一,一對(duì)多的類(lèi)就可以完成,這篇文章主要給大家介紹了關(guān)于Mybatis一對(duì)多和多對(duì)一處理的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • SpringBoot3整合MyBatis出現(xiàn)異常:Property?'sqlSessionFactory'or?'sqlSessionTemplate'?are?required

    SpringBoot3整合MyBatis出現(xiàn)異常:Property?'sqlSessionFactory&a

    這篇文章主要介紹了SpringBoot3整合MyBatis報(bào)錯(cuò):Property?‘sqlSessionFactory‘?or?‘sqlSessionTemplate‘?are?required,其實(shí)不是個(gè)大問(wèn)題,只是自己編碼時(shí)遇到了,然后總結(jié)總結(jié)分享一下,如果有遇到類(lèi)似問(wèn)題的,可以參考一下
    2022-11-11
  • Java線(xiàn)程變量ThreadLocal源碼分析

    Java線(xiàn)程變量ThreadLocal源碼分析

    ThreadLocal用來(lái)提供線(xiàn)程內(nèi)部的局部變量,不同的線(xiàn)程之間不會(huì)相互干擾,這種變量在多線(xiàn)程環(huán)境下訪(fǎng)問(wèn)時(shí)能保證各個(gè)線(xiàn)程的變量相對(duì)獨(dú)立于其他線(xiàn)程內(nèi)的變量,在線(xiàn)程的生命周期內(nèi)起作用,可以減少同一個(gè)線(xiàn)程內(nèi)多個(gè)函數(shù)或組件之間一些公共變量傳遞的復(fù)雜度
    2022-08-08
  • SpringBoot導(dǎo)出PDF的四種實(shí)現(xiàn)方法詳解

    SpringBoot導(dǎo)出PDF的四種實(shí)現(xiàn)方法詳解

    在Spring?Boot應(yīng)用程序中實(shí)現(xiàn)PDF導(dǎo)出功能,可以選擇多種庫(kù)和技術(shù)棧,本文為大家整理了四種常見(jiàn)的方法,感興趣的小伙伴可以參考一下
    2025-02-02
  • JAVA利用接口實(shí)現(xiàn)多繼承問(wèn)題的代碼實(shí)操演示

    JAVA利用接口實(shí)現(xiàn)多繼承問(wèn)題的代碼實(shí)操演示

    Java語(yǔ)言并不支持多繼承,這是由于多繼承會(huì)帶來(lái)許多復(fù)雜的問(wèn)題,例如"菱形問(wèn)題"等,下面這篇文章主要給大家介紹了關(guān)于JAVA利用接口實(shí)現(xiàn)多繼承問(wèn)題的相關(guān)資料,需要的朋友可以參考下
    2024-03-03
  • AOP之事務(wù)管理<aop:advisor>的兩種配置方式

    AOP之事務(wù)管理<aop:advisor>的兩種配置方式

    這篇文章主要介紹了AOP之事務(wù)管理<aop:advisor>的兩種配置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • JAVA后臺(tái)轉(zhuǎn)換成樹(shù)結(jié)構(gòu)數(shù)據(jù)返回給前端的實(shí)現(xiàn)方法

    JAVA后臺(tái)轉(zhuǎn)換成樹(shù)結(jié)構(gòu)數(shù)據(jù)返回給前端的實(shí)現(xiàn)方法

    這篇文章主要介紹了JAVA后臺(tái)轉(zhuǎn)換成樹(shù)結(jié)構(gòu)數(shù)據(jù)返回給前端的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03

最新評(píng)論

保定市| 康平县| 永兴县| 晋江市| 大姚县| 江源县| 百色市| 麻江县| 茂名市| 增城市| 师宗县| 鸡泽县| 花莲县| 城固县| 霍林郭勒市| 灵川县| 固始县| 昌图县| 吴堡县| 莱阳市| 磐安县| 芮城县| 玉门市| 长葛市| 晋城| 图木舒克市| 且末县| 揭东县| 广水市| 河东区| 永善县| 济宁市| 融水| 德昌县| 玉田县| 合川市| 玛多县| 安庆市| 鄯善县| 凯里市| 桃园市|