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

SpringBoot中MybatisX插件的簡單使用教程(圖文)

 更新時(shí)間:2023年06月30日 10:24:50   作者:啊陳曉  
MybatisX 是一款基于 IDEA 的快速開發(fā)插件,方便在使用mybatis以及mybatis-plus開始時(shí)簡化繁瑣的重復(fù)操作,本文主要介紹了SpringBoot中MybatisX插件的簡單使用教程,感興趣的可以了解一下

1.什么是MybatisX?

MybatisX 是一款基于 IDEA 的快速開發(fā)插件,方便在使用mybatis以及mybatis-plus開始時(shí)簡化繁瑣的重復(fù)操作,提高開發(fā)速率。

2.使用MybatisX的好處

  • 節(jié)省大量持久層代碼開發(fā)時(shí)間
  • 強(qiáng)大的功能為業(yè)務(wù)編寫提供各類支持
  • 配置簡單,告別各類復(fù)雜的配置文件 

3.如何使用MybatisX?

1.創(chuàng)建一個(gè)簡單的數(shù)據(jù)庫

2.創(chuàng)建一個(gè)簡單的Springboot工程

3.在pom.xml文件中引入mybatis-plus依賴

pom.xml

        <!--mybatisPlus-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.1</version>
        </dependency>

4.在File->Settings->Plugins下載MybatiX插件 

 5.兩下SHIFT鍵搜索database進(jìn)入數(shù)據(jù)庫

6.新建Mysql連接 

 輸入用戶、密碼及數(shù)據(jù)庫名

 當(dāng)Test Connection時(shí)會(huì)提示這么一段話:這是時(shí)區(qū)未設(shè)置問題

 根據(jù)提示來到Advanced,找到severTimezone,將其設(shè)置為GMT(Greenwich Mean Time 格林尼治標(biāo)準(zhǔn)時(shí)間)

此時(shí)再測試連接會(huì)發(fā)現(xiàn)已經(jīng)成功

 這時(shí)候我們就可以看見我們想要連接的數(shù)據(jù)庫和其對應(yīng)的表等信息了 

右鍵對應(yīng)的表,我們可以看到MybatiX-Generator

點(diǎn)擊后我們會(huì)看到這樣一個(gè)頁面,我們可以在這個(gè)頁面中設(shè)置需要消除的前后綴、文件存放目錄等...

點(diǎn)擊Next,在下面是一些配置,我們勾選Mybatis-Plus的最新版本Mybatix-Plus 3 和 簡化開發(fā)的Lombok 

點(diǎn)擊Finish,我們可以看到MybatisX為我們自動(dòng)生成了該表對應(yīng)的實(shí)體類、Mapper文件、Service和相對應(yīng)的接口

在yaml中對數(shù)據(jù)庫進(jìn)行配置:

application.yaml

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/user?characterEncoding=utf-8&useSSL=false&serverTimezone=GMT
    username: root
    password: password

控制層編寫方法,使用到Mybatis-Plus中的條件構(gòu)造器:

package com.example.mybatixtest.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mybatixtest.pojo.User;
import com.example.mybatixtest.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
    @Autowired
    UserService userService;
    @GetMapping("/test")
    public User test(){
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("user_id",1);
        User user = userService.getOne(userQueryWrapper);
        return user;
    }
}

訪問成功 

至此,MybatiX整合springboot的簡單配置結(jié)束,更多相關(guān)SpringBoot MybatisX內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論