全網(wǎng)最新springboot整合mybatis-plus的過(guò)程
一,簡(jiǎn)介
1. 什么是mybatis-plus
MyBatis-Plus(簡(jiǎn)稱(chēng)MP)是一個(gè)MyBatis的增強(qiáng)工具,旨在在MyBatis的基礎(chǔ)上只做增強(qiáng)不做改變,以簡(jiǎn)化開(kāi)發(fā)、提高效率。MyBatis-Plus保持了MyBatis原有的所有特性,同時(shí)增加了一些實(shí)用的功能,使得開(kāi)發(fā)者能夠更加便捷地進(jìn)行數(shù)據(jù)庫(kù)操作。以下是MyBatis-Plus的一些主要特點(diǎn)和功能:
2.mybatis-plus特點(diǎn)
- 無(wú)侵入:引入MyBatis-Plus不會(huì)對(duì)現(xiàn)有的MyBatis工程產(chǎn)生影響,可以無(wú)縫集成到現(xiàn)有的項(xiàng)目中。
- 損耗?。?jiǎn)?dòng)時(shí)自動(dòng)注入基本的CRUD操作,幾乎不消耗額外的性能,可以直接面向?qū)ο蟛僮鲾?shù)據(jù)庫(kù)。
- 強(qiáng)大的CRUD操作:內(nèi)置通用Mapper、通用Service,通過(guò)少量配置即可實(shí)現(xiàn)單表的大部分CRUD操作。同時(shí),MyBatis-Plus提供了強(qiáng)大的條件構(gòu)造器,滿足復(fù)雜的查詢(xún)需求。
- 支持Lambda形式調(diào)用:利用Lambda表達(dá)式方便地編寫(xiě)查詢(xún)條件,避免了字段名稱(chēng)錯(cuò)誤的問(wèn)題。
- 支持主鍵自動(dòng)生成:提供了多種主鍵生成策略,包括分布式唯一ID生成器,解決了主鍵問(wèn)題。
- 支持ActiveRecord模式:通過(guò)繼承特定的基類(lèi),可以像操作對(duì)象一樣操作數(shù)據(jù)庫(kù)。
- 支持自定義全局通用操作:允許開(kāi)發(fā)者注入自己的通用方法。
- 內(nèi)置分頁(yè)插件:基于MyBatis的物理分頁(yè),開(kāi)發(fā)者可以輕松實(shí)現(xiàn)分頁(yè)查詢(xún)。
- 支持多種數(shù)據(jù)庫(kù):兼容MySQL、MariaDB、Oracle、DB2、H2、HSQL、SQLite、PostgreSQL、SQL Server等多種數(shù)據(jù)庫(kù)。
- 內(nèi)置性能分析插件:可以輸出SQL語(yǔ)句及其執(zhí)行時(shí)間,有助于快速定位慢查詢(xún)。
- 內(nèi)置全局?jǐn)r截插件:提供全表刪除、更新操作的智能分析阻斷,防止誤操作。
二,搭建基本環(huán)境
1. 導(dǎo)入基本依賴(lài):
<!--mybatis-plus依賴(lài)-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.7</version>
</dependency>
<!--mysql連接依賴(lài)-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<!--連接池依賴(lài)-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.18</version>
</dependency>2. 編寫(xiě)配置文件
spring:
data:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis_study?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: root
type: com.alibaba.druid.pool.DruidDataSource3. 創(chuàng)建實(shí)體類(lèi)
package org.example.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.util.Date;
@TableName("student")
public class Student {
@TableId(type = IdType.AUTO)
private int id;
private String studentNumber;
private String name;
private int gender;
// 0 表示女性,1 表示男性
private Date dateOfBirth;
// Getters and Setters
}4. 編寫(xiě)controller層
package org.example.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/students")
public class StudentController {
}5. 編寫(xiě)service接口
package org.example.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.example.pojo.Student;
public interface StudentService extends IService<Student> {
}6. 編寫(xiě)service層
package org.example.service.serviceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.mapper.StudentMapper;
import org.example.pojo.Student;
import org.example.service.StudentService;
import org.springframework.stereotype.Service;
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {
}7. 編寫(xiě)mapper層
package org.example.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.example.pojo.Student;
@Mapper
public interface StudentMapper extends BaseMapper<Student> {
}三,基本知識(shí)介紹
1. 基本注解 @TableName
主要用于指定表名,實(shí)現(xiàn)實(shí)體類(lèi)與表名的綁定,作用于類(lèi)上,適用于表名與實(shí)體類(lèi)名稱(chēng)不統(tǒng)一的情況,統(tǒng)一的情況可以不用寫(xiě)。

import com.baomidou.mybatisplus.annotation.TableName;
//此處表名稱(chēng)為t_user,實(shí)體類(lèi)名稱(chēng)為User不統(tǒng)一
@TableName("t_user")
public class User {
private Long id;
private String name;
private Integer age;
private String email;
// Getters and Setters
}如果所有的表結(jié)構(gòu)與實(shí)體類(lèi)只是多了一個(gè)前綴,可以直接在配置文件里面配置全局的前綴,就可以不使用注解了,兩種方式都可以,根據(jù)具體場(chǎng)景選擇,配置如下:
mybatis-plus:
global-config:
db-config:
table-prefix: t_@TableId
作用于主鍵上,指明主鍵字段,并設(shè)置主鍵的生成方式。
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
@TableName("user_info") // 指定該實(shí)體類(lèi)對(duì)應(yīng)的數(shù)據(jù)表名
public class UserInfo {
//此處value也可以作用于映射,當(dāng)實(shí)體類(lèi)中
//的id字段名和數(shù)據(jù)庫(kù)中的字段名不相同時(shí),可以使用其屬性做增強(qiáng)
@TableId(value = "id", type = IdType.AUTO) // 標(biāo)記為主鍵,并指定主鍵生成策略為自增
private Long id;
private String username;
private String password;
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}注解屬性:
value:指定表中主鍵字段,多用于主鍵字段和實(shí)體類(lèi)字段不同意
type:id生成策略
對(duì)于IdType做出如下說(shuō)明:
| 屬性 | 說(shuō)明 | 適用場(chǎng)景 |
|---|---|---|
AUTO | 數(shù)據(jù)庫(kù)自增主鍵 | 適用于 MySQL、SQL Server 等支持自增主鍵的數(shù)據(jù)庫(kù) |
NONE | 不使用任何主鍵生成策略 | 通常用于主鍵已經(jīng)存在的情況 |
ASSIGN_ID | 全局唯一ID(默認(rèn)基于Snowflake算法生成) | 適用于分布式系統(tǒng),確保全局唯一性 |
ASSIGN_UUID | 全局唯一UUID,生成32位的字符串 | 適用于需要字符串主鍵的場(chǎng)景 |
INPUT | 自定義輸入主鍵值 | 適用于某些特殊場(chǎng)景,如導(dǎo)入數(shù)據(jù)時(shí)需要手動(dòng)指定主鍵 |
改注解作用眾多,多用于表字段和實(shí)體類(lèi)字段名稱(chēng)不統(tǒng)一,做映射處理,也可用于零時(shí)字段,不存入數(shù)據(jù)庫(kù),或者是一些字段的填充處理(此處需要編寫(xiě)填充處理器)。

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import java.util.Date;
@TableName("user_info")
public class UserInfo {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@TableField("username")
private String username;
//此字段不參與查詢(xún)
@TableField("password", select=false )
private String password;
@TableField("email")
private String email;
//注意,此處應(yīng)該編寫(xiě)相應(yīng)的填充邏輯
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@TableField(value = "update_time", fill = FieldFill.UPDATE)
private Date updateTime;
@TableField(exist = false)
private String tempField; // 臨時(shí)字段,不在數(shù)據(jù)庫(kù)中
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getTempField() {
return tempField;
}
public void setTempField(String tempField) {
this.tempField = tempField;
}
}屬性說(shuō)明:
value:同上面注解一樣,用于字段綁定,單個(gè)屬性的時(shí)候可以不寫(xiě)
select:在值為false的情況下用于設(shè)置不參查詢(xún),查詢(xún)之后不會(huì)返回回來(lái)
exist :用于類(lèi)中的零時(shí)變量,數(shù)據(jù)庫(kù)中沒(méi)有該字段,只在java中使用
fill:用于自動(dòng)填充,比如create_time,update_time這一類(lèi),但需要編寫(xiě)相應(yīng)的處理器
對(duì)應(yīng)處理器代碼:
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
this.strictInsertFill(metaObject, "updateTime", Date.class, new Date());
}
@Override
public void updateFill(MetaObject metaObject) {
this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
}
}@TableLogic
該字段用于指定邏輯刪除的字段,當(dāng)執(zhí)行刪除語(yǔ)句時(shí),做更新操作,只改變當(dāng)前字段的值,設(shè)置為刪除狀態(tài),數(shù)據(jù)不做真實(shí)處理,查詢(xún)時(shí)也只查詢(xún)狀態(tài)為未刪除的數(shù)據(jù)(此過(guò)程不需要手動(dòng)實(shí)現(xiàn),mybatis-plus已經(jīng)幫忙實(shí)現(xiàn)了,我們只需要添加字段,設(shè)置相應(yīng)的狀態(tài)值)注:該字段也需要加入到對(duì)應(yīng)的表里
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
@TableName("user_info")
public class UserInfo {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
private String username;
private String password;
private String email;
@TableLogic
private Integer isDeleted;
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getIsDeleted() {
return isDeleted;
}
public void setIsDeleted(Integer isDeleted) {
this.isDeleted = isDeleted;
}
}在配置文件中添加如下配置:
mybatis-plus:
global-config:
db-config:
# 邏輯刪除字段名
logic-delete-field: deleted
# 邏輯刪除字面值:未刪除為0
logic-not-delete-value: 0
# 邏輯刪除字面值:刪除為1
logic-delete-value: 1@Version
用于配置樂(lè)觀鎖字段,配置之后的更新操作都會(huì)先去比較版本,然后在去操作,整體采用cas機(jī)制實(shí)現(xiàn)。注:該字段也需要加入到對(duì)應(yīng)的表里
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.Version;
@TableName("order_info")
public class OrderInfo {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
private String orderNo;
private Double amount;
@Version
private Integer version;
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getOrderNo() {
return orderNo;
}
public void setOrderNo(String orderNo) {
this.orderNo = orderNo;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
this.amount = amount;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
}此處需加相關(guān)的攔截器:
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MyBatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
return interceptor;
}
}樂(lè)觀鎖的作用:
樂(lè)觀鎖假設(shè)在并發(fā)環(huán)境中沖突較少,因此在操作數(shù)據(jù)時(shí)不立即獲取鎖,而是等到提交更新時(shí)才檢查是否有其他事務(wù)修改過(guò)數(shù)據(jù)。如果發(fā)現(xiàn)數(shù)據(jù)已被修改,則更新失敗,通常會(huì)拋出異常。
特點(diǎn):在提交更新時(shí)檢查版本號(hào),如果版本號(hào)匹配則更新成功,否則更新失敗。
效果:多個(gè)事務(wù)可以同時(shí)讀取和處理數(shù)據(jù),但在提交更新時(shí)會(huì)檢查版本號(hào),確保數(shù)據(jù)的一致性。
@Transient
作用于實(shí)體類(lèi)字段,使其不參與數(shù)據(jù)庫(kù)的操作,其中包括(Insert,Update,Select),@TableField(exist=false)作用相同,充當(dāng)零時(shí)變量。
@TableName("user")
public class User {
@TableId(type = IdType.AUTO)
private Long id;
private String name;
@Transient
private String tempField;
// getters and setters
}2. Wrapper的介紹*
概念:MyBatisPlus提供了QueryWrapper、LambdaQueryWrapper、UpdateWrapper和LambdaUpdateWrapper等條件類(lèi),大大簡(jiǎn)化了我們的開(kāi)發(fā),可以使代碼更加清晰和易于管理,其中包括多條件查詢(xún)、排序、條件優(yōu)先級(jí)以及有條件時(shí)才加入條件的場(chǎng)景,并提供了示例代碼展示如何進(jìn)行數(shù)據(jù)庫(kù)查詢(xún)和更新操作。
大致的條件(此處粗略列舉):
| 方法 | 描述 |
|---|---|
| eq | 等于 |
| ne | 不等于 |
| gt | 大于 |
| ge | 大于等于 |
| lt | 小于 |
| le | 小于等于 |
| like | 模糊查詢(xún) |
| notLike | 反向模糊查詢(xún) |
| in | 在某集合內(nèi) |
| notIn | 不在某集合內(nèi) |
| isNull | 為空 |
| isNotNull | 不為空 |
| between | 在某個(gè)區(qū)間內(nèi) |
| notBetween | 不在某個(gè)區(qū)間內(nèi) |
| set | 設(shè)置字段值 |
QueryWrapper
作用于查詢(xún)?cè)O(shè)置查詢(xún)條件。
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
public class UserService {
private UserMapper userMapper;
public List<User> getUsersByConditions() {
// 創(chuàng)建 QueryWrapper 對(duì)象
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
// 添加查詢(xún)條件
queryWrapper.eq("name", "張三")
.ge("age", 18)
.orderByDesc("create_time");
// 執(zhí)行查詢(xún)
return userMapper.selectList(queryWrapper);
}
}此處執(zhí)行的sql語(yǔ)句:
SELECT * FROM user WHERE name = '張三' AND age >= 18 ORDER BY create_time DESC;
UpdateWrapper
作用于更新設(shè)置條件。
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
public class UserService {
private UserMapper userMapper;
public int updateUserById() {
// 創(chuàng)建 UpdateWrapper 對(duì)象
UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
// 添加更新條件
updateWrapper.eq("id", 1);
// 創(chuàng)建要更新的對(duì)象
User user = new User();
user.setName("李四");
// 執(zhí)行更新
return userMapper.update(user, updateWrapper);
}
}此處執(zhí)行的sql語(yǔ)句:
UPDATE user SET name = '李四' WHERE id = 1;
LambdaQueryWrapper
在QueryWrapper做了增強(qiáng),作用一樣,用于設(shè)置查詢(xún)條件。
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
public class UserService {
private UserMapper userMapper;
public List<User> getUsersByLambdaConditions() {
// 創(chuàng)建 LambdaQueryWrapper 對(duì)象
LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
// 添加查詢(xún)條件
lambdaQueryWrapper.eq(User::getName, "張三")
.ge(User::getAge, 18)
.orderByDesc(User::getCreateTime);
// 執(zhí)行查詢(xún)
return userMapper.selectList(lambdaQueryWrapper);
}
}此處執(zhí)行的sql語(yǔ)句:
SELECT * FROM user WHERE name = '張三' AND age >= 18 ORDER BY create_time DESC;
LambdaUpdateWrapper
在UpdateWrapper做了增強(qiáng),作用一樣,用于設(shè)置跟新條件。
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
public class UserService {
private UserMapper userMapper;
public int updateUserByIdWithLambda() {
// 創(chuàng)建 LambdaUpdateWrapper 對(duì)象
LambdaUpdateWrapper<User> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
// 添加更新條件
lambdaUpdateWrapper.eq(User::getId, 1);
// 創(chuàng)建要更新的對(duì)象
User user = new User();
user.setName("李四");
// 執(zhí)行更新
return userMapper.update(user, lambdaUpdateWrapper);
}
}此處執(zhí)行的sql語(yǔ)句:
UPDATE user SET name = '李四' WHERE id = 1;
Wrappers
用于更簡(jiǎn)便的條件設(shè)置
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
public class UserService {
private UserMapper userMapper;
public List<User> getUsersByConditionsUsingWrappers() {
// 創(chuàng)建 QueryWrapper 對(duì)象
QueryWrapper<User> queryWrapper = Wrappers.<User>query()
.eq("name", "張三")
.ge("age", 18)
.orderByDesc("create_time");
// 執(zhí)行查詢(xún)
return userMapper.selectList(queryWrapper);
}
}此處執(zhí)行的sql語(yǔ)句:
SELECT * FROM user WHERE name = '張三' AND age >= 18 ORDER BY create_time DESC;
3. 分頁(yè)查詢(xún)
1. 配置相應(yīng)的攔截器
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MyBatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return interceptor;
}
}2. 實(shí)現(xiàn)分頁(yè)邏輯
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.User;
import com.example.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserService {
@Autowired
private UserMapper userMapper;
public IPage<User> getUserPage(int current, int size) {
// 創(chuàng)建 Page 對(duì)象,傳入當(dāng)前頁(yè)碼和每頁(yè)大小
Page<User> page = new Page<>(current, size);
// 創(chuàng)建 QueryWrapper 對(duì)象,添加查詢(xún)條件
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("status", 1)
.orderByDesc("create_time");
// 執(zhí)行分頁(yè)查詢(xún)
IPage<User> userPage = userMapper.selectPage(page, queryWrapper);
// 獲取分頁(yè)數(shù)據(jù)
List<User> users = userPage.getRecords();
// 獲取總記錄數(shù)
long total = userPage.getTotal();
// 獲取當(dāng)前頁(yè)碼
int current = userPage.getCurrent();
// 獲取每頁(yè)大小
int size = userPage.getSize();
// 獲取總頁(yè)數(shù)
int pages = userPage.getPages();
return userPage;
}
}執(zhí)行對(duì)應(yīng)的sql語(yǔ)句是:
-- 分頁(yè)查詢(xún) SELECT * FROM user WHERE status = 1 ORDER BY create_time DESC LIMIT 0, 10; -- 當(dāng)前頁(yè)碼為1,每頁(yè)大小為10
四,結(jié)語(yǔ)
在本文中,我們?cè)敿?xì)介紹了 MyBatis-Plus 的核心功能和使用方法,包括如何配置分頁(yè)插件、編寫(xiě)分頁(yè)查詢(xún)代碼、使用各種 Wrapper 構(gòu)建復(fù)雜查詢(xún)條件等。通過(guò)這些內(nèi)容,相信你已經(jīng)對(duì) MyBatis-Plus 有了更深入的了解,并能夠在實(shí)際項(xiàng)目中靈活應(yīng)用這些功能。
MyBatis-Plus 作為一個(gè)強(qiáng)大的 MyBatis 增強(qiáng)工具,不僅簡(jiǎn)化了數(shù)據(jù)訪問(wèn)層的開(kāi)發(fā)工作,還提供了許多便捷的功能,如分頁(yè)查詢(xún)、鏈?zhǔn)骄幊?、?lè)觀鎖等。它能夠顯著提升開(kāi)發(fā)效率,減少重復(fù)代碼,使你的項(xiàng)目更加簡(jiǎn)潔和高效。
如果你在閱讀本文后對(duì) MyBatis-Plus 感興趣,不妨在自己的項(xiàng)目中嘗試一下。實(shí)踐是最好的老師,通過(guò)實(shí)際操作,你會(huì)更加深刻地理解這些功能的奧妙。同時(shí),也歡迎你在評(píng)論區(qū)分享你的使用經(jīng)驗(yàn)和遇到的問(wèn)題,我們一起探討和解決。
最后,感謝你花時(shí)間閱讀本文,希望本文能為你帶來(lái)幫助。如果你覺(jué)得本文對(duì)你有幫助,別忘了點(diǎn)贊和分享,讓更多的人受益。讓我們一起在技術(shù)的道路上不斷前行,共同成長(zhǎng)!
- SpringBoot整合Mybatis-plus實(shí)現(xiàn)多級(jí)評(píng)論功能
- SpringBoot3整合mybatis-plus的實(shí)現(xiàn)
- Springboot3整合Mybatis-plus3.5.3報(bào)錯(cuò)問(wèn)題解決
- SpringBoot整合mybatis-plus實(shí)現(xiàn)分頁(yè)查詢(xún)功能
- springboot3.2整合mybatis-plus詳細(xì)代碼示例
- SpringBoot3和mybatis-plus整合出現(xiàn)的問(wèn)題解決辦法
- SpringBoot3.2.2整合MyBatis-Plus3.5.5依賴(lài)不兼容的問(wèn)題解決
- SpringBoot整合Mybatis-Plus實(shí)現(xiàn)關(guān)聯(lián)查詢(xún)
- SpringBoot3.3.X整合Mybatis-Plus的實(shí)現(xiàn)示例
相關(guān)文章
java 過(guò)濾器filter防sql注入的實(shí)現(xiàn)代碼
下面小編就為大家?guī)?lái)一篇java 過(guò)濾器filter防sql注入的實(shí)現(xiàn)代碼。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-08
Java輸入流Scanner/BufferedReader使用方法示例
這篇文章主要介紹了Java輸入流Scanner/BufferedReader使用方法,大家看示例吧2013-11-11
SpringBoot4.0整合RabbitMQ死信隊(duì)列詳解
本文主要介紹了SpringBoot4.0整合RabbitMQ死信隊(duì)列詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2026-02-02
RestTemplate對(duì)HttpClient的適配源碼解讀
這篇文章主要為大家介紹了RestTemplate對(duì)HttpClient的適配源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10
Java使用代理進(jìn)行網(wǎng)絡(luò)連接方法示例
這篇文章主要介紹了Java使用代理進(jìn)行網(wǎng)絡(luò)連接方法示例,內(nèi)容十分詳細(xì),需要的朋友可以參考下。2017-09-09
基于XML配置Spring的自動(dòng)裝配過(guò)程解析
這篇文章主要介紹了基于XML配置Spring的自動(dòng)裝配過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-10-10

