Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize logical deletion by mybatisPlus

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to achieve logical deletion of mybatisPlus". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how to achieve logical deletion of mybatisPlus"!

Most of the configuration introductions about the logical deletion of mybatisPlus on the Internet are problematic, probably because the official website has been updated! The error is shown in the figure:

The correct configuration is:

How to configure SpringBoot:

Application.yml join configuration (if your default value is the same as mp default, this configuration may not be available):

Yml file (the difference is that there is an extra path db-config, students have taken a closer look at it)

Mybatis-plus: global-config: db-config: logic-delete-value: 1 # logical deleted value (default is 1) logic-not-delete-value: 0 # logical undeleted value (default is 0)

Injection of bean for logically deleted interceptors

Import com.baomidou.mybatisplus.core.injector.ISqlInjector;import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration; @ Configurationpublic class MyBatisPlusConfiguration {@ Bean public ISqlInjector sqlInjector () {return new LogicSqlInjector ();}}

Add @ TableLogic annotation to the entity class field

@ TableLogicprivate Integer deleted

Effect: use mp native method to delete and search with logical deletion function (self-written xml will not)

Update user set deleted=1 where id = 1 when example is deleted, select * from user where deleted=0 when and deleted=0 is searched

Attachment description

Logical deletion is a scheme to facilitate data recovery and protect the value of the data itself, but it is actually deletion.

If you need to find out again, you should not use logical deletion, but in a state.

For example, employee turnover and account locking should be a status field, and logical deletion should not be used in this scenario.

If you really need to find deleted data, if the boss needs to view the statistical summary of all historical data, please write sql separately.

At this point, I believe you have a deeper understanding of "how to achieve logical deletion in mybatisPlus". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report