⭐ August more text challenge the third day ⭐, MybatisPlus learning, welcome friends to learn 😁

Code Mantis shrimp is a sand sculpture and interesting young boy, like most friends like listening to music, games, of course, in addition to the interest of writing, Emm… The day is still very long, let us walk together 🌈

Welcome friends to pay attention to my public number: JavaCodes, although the name with Java, but the scope of more than Java field oh 😁, look forward to your attention ❤

The original link⭐MybatisPlus learning notes ⭐ (3) To achieve logical deletion, paging

Look at the MybatisPlus module for this link


1. Logical deletion

Description:

Only for auto-injected SQL:

  • Insert: No restrictions
  • Lookup: Append the WHERE condition to filter out the deleted data, and the WHERE condition generated using wrapper.entity ignores this field
  • Update: Append where condition to prevent update to deleted data, and where condition generated using wrapper.entity ignores this field
  • Delete: Convert to update

Such as:

  • Delete: update user set deleted=1 where ID =1 and deleted=0
  • Search: select ID,name,deleted from user where deleted=0

Field types are supported:

  • Support all data types (recommended Integer, Boolean, LocalDateTime)
  • If the database field uses datetime, the logical undeleted value and the deleted value can be configured as a string null, and the other value can be configured as a function to get the value such as now()

Appendix:

  • Logical deletion is a solution to facilitate data recovery, protect the value of the data itself, etc., but it is actually deletion.
  • If you need to check frequently you should not use logical delete, but instead represent it as a state.

==1. Add field deleted== to the database and the corresponding entity class

Add @ to the entity class fieldTableLogicannotations

== make sure to set value and delval, otherwise the following error will be reported. I have been looking for more than an hour for the error ==

==2. Configure the configuration file

Mybtis-plus.global-config.db-config.logic-delete-value =1# Logical deleted value (default is1)
mybatis-plus.global-config.db-config.logic-not-delete-value=0# Logical undeleted value (default is0)
Copy the code

= = = = test

As you can see, the actual SQL being executed is the Update statement, which is the logical delete


2, the realization of paging query

Refer to official documents

1, create a configuration class, add paging plug-in == ==2

You can see that the query results are 8 and 9, because 7 has been logically deleted




The last

I am aCode pipi shrimpI am a mantis shrimp lover who loves to share knowledge. I will keep updating my blog in the future. I look forward to your attention!!

Creation is not easy, if this blog is helpful to you, I hope you can == a key three! ==, thanks for your support, see you next time ~~~

Share the outline

Big factory interview questions column

PC crawler column

App Crawler Column