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依賴
com.baomidou mybatis-plus-boot-starter 3.5.1
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//localhost:3306/user?characterEncoding=utf-8&useSSL=false&serverTimezone=GMT username:root password:password
控制層編寫方法,使用到Mybatis-Plus中的條件構(gòu)造器:
packagecom.example.mybatixtest.controller; importcom.baomidou.mybatisplus.core.conditions.query.QueryWrapper; importcom.example.mybatixtest.pojo.User; importcom.example.mybatixtest.service.UserService; importorg.springframework.beans.factory.annotation.Autowired; importorg.springframework.web.bind.annotation.GetMapping; importorg.springframework.web.bind.annotation.RestController; @RestController publicclassTestController{ @Autowired UserServiceuserService; @GetMapping("/test") publicUsertest(){ QueryWrapperuserQueryWrapper=newQueryWrapper<>(); userQueryWrapper.eq("user_id",1); Useruser=userService.getOne(userQueryWrapper); returnuser; } }
訪問成功
至此,MybatiX整合springboot的簡單配置結(jié)束??!
審核編輯:湯梓紅
-
數(shù)據(jù)庫
+關(guān)注
關(guān)注
7文章
3981瀏覽量
67490 -
spring
+關(guān)注
關(guān)注
0文章
341瀏覽量
15627 -
插件
+關(guān)注
關(guān)注
0文章
342瀏覽量
23333 -
Boot
+關(guān)注
關(guān)注
0文章
154瀏覽量
37355 -
idea
+關(guān)注
關(guān)注
1文章
70瀏覽量
4826 -
SpringBoot
+關(guān)注
關(guān)注
0文章
175瀏覽量
573
原文標(biāo)題:SpringBoot 中 MybatisX 插件的簡單使用教程(超詳細(xì)?。。?/p>
文章出處:【微信號(hào):AndroidPush,微信公眾號(hào):Android編程精選】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評(píng)論請先 登錄
SpringBoot應(yīng)用啟動(dòng)運(yùn)行run方法
為什么建議你替換掉SpringBoot框架中的Tomcat?
什么是 SpringBoot?

SpringBoot常用注解及使用方法1
SpringBoot常用注解及使用方法2
SpringBoot的核心注解1

SpringBoot的核心注解2

如何在SpringBoot中解決Redis的緩存穿透等問題
SpringBoot插件化開發(fā)模式

評(píng)論