国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

SpringBoot 3.x整合Fluent Mybatis極簡流程

這篇具有很好參考價值的文章主要介紹了SpringBoot 3.x整合Fluent Mybatis極簡流程。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

此為基礎(chǔ)配置,不包括其他高級配置,需要其他高級配置請查閱官方文檔:[fluent mybatis特性總覽 - Wiki - Gitee.com](https://gitee.com/fluent-mybatis/fluent-mybatis/wikis/fluent mybatis特性總覽)

版本信息

  • Spring Boot 版本:3.1.2
  • Fluent Mybatis 版本:1.9.9
  • mybatis-spring-boot-starter 版本:3.0.0
  • JDK 版本:JDK17

Maven依賴

spring boot依賴

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.2</version>
        <relativePath/> 
    </parent>

<dependencies>
	<dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
     </dependency>
    
        <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>
     

Fluent Mybatis和MySQL數(shù)據(jù)庫依賴


<properties>
    <fluent-mybatis.version>1.9.9</fluent-mybatis.version>
</properties>
<dependencies>
    <!--mysql驅(qū)動-->
    <dependency>
        <groupId>com.mysql</groupId>
        <artifactId>mysql-connector-j</artifactId>
        <scope>runtime</scope>
    </dependency>

 	<!-- 引入fluent-mybatis 運(yùn)行依賴包, scope為compile -->
    <dependency>
        <groupId>com.github.atool</groupId>
        <artifactId>fluent-mybatis</artifactId>
        <version>${fluent-mybatis.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis-spring</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- 引入fluent-mybatis-processor, scope設(shè)置為provider 編譯需要,運(yùn)行時不需要 -->
    <dependency>
        <groupId>com.github.atool</groupId>
        <artifactId>fluent-mybatis-processor</artifactId>
        <scope>provided</scope>
        <version>${fluent-mybatis.version}</version>
    </dependency>

    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>3.0.0</version>
    </dependency>
</dependencies>

添加配置類

import cn.org.atool.fluent.mybatis.spring.MapperFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisConfig {

    @Bean
    public MapperFactory mapperFactory() {
        return new MapperFactory();
    }

}

配置掃描

在啟動類添加mapper路徑,注意Fluent的Mapper是不需要手動編寫的,直接編譯生成即可,在 target 目錄下可以看到生成出來的文件。

@MapperScan("com.example.fluent.mapper")

SpringBoot 3.x整合Fluent Mybatis極簡流程,Mybatis,spring boot,mybatis,后端

創(chuàng)建表

創(chuàng)建 test測試庫,并創(chuàng)建 person表。

CREATE TABLE `person` (
  `id` int NOT NULL AUTO_INCREMENT,
  `first_name` varchar(255) NOT NULL,
  `last_name` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `age` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10000001 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;



INSERT INTO `test`.`person` (`id`, `first_name`, `last_name`, `email`, `age`) VALUES (1, 'First0000001', 'Last0000001', 'email0000001@example.com', 92);
INSERT INTO `test`.`person` (`id`, `first_name`, `last_name`, `email`, `age`) VALUES (2, 'First0000002', 'Last0000002', 'email0000002@example.com', 33);
INSERT INTO `test`.`person` (`id`, `first_name`, `last_name`, `email`, `age`) VALUES (3, 'First0000003', 'Last0000003', 'email0000003@example.com', 19);

添加實(shí)體類

import cn.org.atool.fluent.mybatis.annotation.FluentMybatis;
import cn.org.atool.fluent.mybatis.annotation.TableId;
import cn.org.atool.fluent.mybatis.base.IEntity;
import lombok.Data;

@FluentMybatis(table = "person")
@Data
public class Person implements IEntity {

    @TableId //主鍵,不指定默認(rèn)主鍵自增
    private Long id;
    private String firstName;
    private String lastName;
    private String email;
    private int age;

}

添加測試接口

@RestController
public class PersonController {

    @Resource
    private PersonMapper personMapper;

    @GetMapping("/data")
    public Object getData() {
        Person person = personMapper.findById(1); //查詢ID為1的數(shù)據(jù)
        return person;
    }

}

配置文件添加數(shù)據(jù)庫連接信息

server:
  port: 8002 //指定8002端口運(yùn)行

spring:
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://192.168.2.6:3306/test?useSSL=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
    username: root
    password: root

測試接口

使用postman請求 http://localhost:8002/data 接口,測試是否可以拿到 id 為1的數(shù)據(jù)

SpringBoot 3.x整合Fluent Mybatis極簡流程,Mybatis,spring boot,mybatis,后端

可以看到結(jié)果是可以拿到的,整合完成。

這個例子是很簡單的,很多參數(shù)都沒有配置,比如下劃線轉(zhuǎn)駝峰之類的,有需要的可以去官方文檔查詢相關(guān)配置,這篇文章里就不贅述了。文章來源地址http://www.zghlxwxcb.cn/news/detail-640395.html

到了這里,關(guān)于SpringBoot 3.x整合Fluent Mybatis極簡流程的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Spring Boot 整合MyBatis(超詳細(xì))

    Spring Boot 整合MyBatis(超詳細(xì))

    ??前言 本篇博文關(guān)于Spring Boot 整合MyBatis,希望你能夠喜歡 ??個人主頁:晨犀主頁 ??個人簡介:大家好,我是晨犀,希望我的文章可以幫助到大家,您的滿意是我的動力???? ??歡迎大家:這里是CSDN,我總結(jié)知識的地方,歡迎來到我的博客,感謝大家的觀看?? 如果文章

    2024年02月11日
    瀏覽(21)
  • 在Spring Boot中整合MyBatis

    第1步:添加依賴: 在pom.xml文件中添加MyBatis和MySQL JDBC驅(qū)動的依賴。如果你使用的是Maven,配置如下: 第2步:配置數(shù)據(jù)源 DataSource: 在application.properties或application.yml文件中配置數(shù)據(jù)庫連接信息: 第3步:(可選)配置MyBatis全局配置文件: 如果你需要自定義MyBatis的全局配置,

    2024年01月24日
    瀏覽(17)
  • Spring Boot整合MyBatis-Plus

    Spring Boot整合MyBatis-Plus

    引言 在現(xiàn)代軟件開發(fā)中,我們經(jīng)常需要處理大量的數(shù)據(jù)。為了有效地管理這些數(shù)據(jù),我們需要使用一些強(qiáng)大的框架。其中,Spring Boot和MyBatis-Plus是兩個非常流行的框架。Spring Boot是一個基于Spring的開源Java框架,可以用于創(chuàng)建獨(dú)立的、生產(chǎn)級別的Spring應(yīng)用。MyBatis-Plus是一個MyB

    2024年01月19日
    瀏覽(32)
  • Spring Boot 整合MyBatis-Plus

    Spring Boot 整合MyBatis-Plus

    ??前言 本篇博文是關(guān)于Spring Boot 整合MyBatis-Plus的,希望你能夠喜歡?? ??個人主頁:晨犀主頁 ??個人簡介:大家好,我是晨犀,希望我的文章可以幫助到大家,您的滿意是我的動力???? ??歡迎大家:這里是CSDN,我總結(jié)知識的地方,歡迎來到我的博客,感謝大家的觀看??

    2024年02月11日
    瀏覽(32)
  • Spring Boot3整合MyBatis Plus

    Spring Boot3整合MyBatis Plus

    目錄 1.前置條件 2.導(dǎo)坐標(biāo) 3.配置數(shù)據(jù)源 4.mybatis-plus基礎(chǔ)配置 5.配置mapper掃描路徑 6.MyBatis Plus代碼生成器整合 1.導(dǎo)坐標(biāo) 2.編寫代碼生成邏輯 7.整合Druid連接池 已經(jīng)初始化好一個spring boot項(xiàng)目且版本為3X,項(xiàng)目可正常啟動 初始化教程: 新版idea創(chuàng)建spring boot項(xiàng)目-CSDN博客 https://blog

    2024年01月23日
    瀏覽(20)
  • Spring Boot整合Mybatis配置多數(shù)據(jù)源

    在之前的事件管理系統(tǒng)博客中有提到動態(tài)的多數(shù)據(jù)源配置 工作中難免需要做幾個工具方便自己偷懶,加上之前的擋板,數(shù)據(jù)源肯定沒法單一配置,所以需要多數(shù)據(jù)源配置。這里介紹兩種配置:動態(tài)數(shù)據(jù)源和固定數(shù)據(jù)源模式。這兩種我在目前的工作的工具開發(fā)中都有用到。 M

    2024年01月23日
    瀏覽(30)
  • spring boot3整合mybatis-plus

    spring boot3整合mybatis-plus

    添加依賴 配置屬性信息 編寫業(yè)務(wù)邏輯測試代碼 配置mybatis-plus分頁插件 配置mybatis-plus之屬性自動填充 如圖所示 1、添加依賴 2、配置屬性 3、編寫測試代碼 4、XML文件 5、測試數(shù)據(jù)是否能走通

    2024年03月12日
    瀏覽(24)
  • Spring Boot中整合MyBatis(基于xml方式&基于注解實(shí)現(xiàn)方式)

    Spring Boot中整合MyBatis(基于xml方式&基于注解實(shí)現(xiàn)方式)

    在Spring Boot中整合MyBatis時,你需要導(dǎo)入JDBC(不需要手動添加)、Druid的相關(guān)依賴、MySQL相關(guān)依賴。 JDBC依賴:在Spring Boot中整合MyBatis時,并不需要顯式地添加JDBC的包依賴。這是因?yàn)?,?dāng)你添加 mybatis-spring-boot-starter 依賴時,它已經(jīng)包含了對JDBC的依賴。 mybatis-spring-boot-starter 是

    2024年02月15日
    瀏覽(38)
  • Spring Boot3.2.2整合MyBatis Plus3.5.5

    Spring Boot3.2.2整合MyBatis Plus3.5.5

    目錄 1.前置條件 2.導(dǎo)坐標(biāo) 3.配置數(shù)據(jù)源 4.mybatis-plus基礎(chǔ)配置 5.配置mapper掃描路徑 6.MyBatis Plus代碼生成器整合 1.導(dǎo)坐標(biāo) 2.編寫代碼生成邏輯 7.整合Druid連接池 已經(jīng)初始化好一個spring boot項(xiàng)目且版本為3X,項(xiàng)目可正常啟動 初始化教程: 新版idea創(chuàng)建spring boot項(xiàng)目-CSDN博客 https://blog

    2024年01月22日
    瀏覽(20)
  • Spring Boot入門(08):整合Mybatis訪問MySQL實(shí)現(xiàn)增刪改查 | 超級詳細(xì),建議收藏

    Spring Boot入門(08):整合Mybatis訪問MySQL實(shí)現(xiàn)增刪改查 | 超級詳細(xì),建議收藏

    ????????在現(xiàn)代的Web應(yīng)用程序中,數(shù)據(jù)庫操作是不可避免的。而Spring Boot作為一款快速開發(fā)框架,其優(yōu)秀的集成能力非常適合與數(shù)據(jù)庫交互,而MyBatis則是一個優(yōu)秀的ORM框架,可以大大簡化我們的數(shù)據(jù)庫操作。本文將結(jié)合Spring Boot和MyBatis,帶您實(shí)現(xiàn)高效的MySQL增刪改查操作,

    2024年02月12日
    瀏覽(28)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包