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

Restore logical deletion method in mysql

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article mainly gives you a brief talk about mysql recovery logic deletion method, related technical terms you can check online or find some related books to add, here will not dabble, we will go straight to the topic, I hope mysql recovery logic deletion method This article can bring you some practical help.

In the front page deleted, also does not show, in fact, the database did not delete, just according to a status field, 0 start, 1 stop thinking to achieve.

Therefore, logical deletion is just to change a field named status to achieve the way whether the front page is displayed. The data itself has not been deleted. To restore, you only need to change back to the status field.

Thinking:

When writing query SQL in XML, add one more condition, the status field in the library

SELECT * FROM md_drainage_basin and basin_name LIKE concat('%',#{basinName},'%') AND state = #{state}ORDER BY sort_order

Then when we give the data to the front-end page, we have to perform default operations in Java code, because the front-end does not pass a status code in the query, and the background generates it by itself.

mdDrainageBasin.setState(0);List list = mdDrainageBasinMapper.findByQuery(mdDrainageBasin);

By default, the status 0 is set to the entity class, and then the query is performed. In this way, only the data with status 0 is seen by the front end.

Logical deletion is to update the status code to 1 and call update instead of delete. However, considering the multi-table relationship, for example, if there is a water system hanging below the basin, a basin should be logically deleted, and the water system below should also be logically deleted without being displayed. At this time, it can be judged that if there is a corresponding water system below the basin, it will not be deleted, otherwise it will be deleted.

MdDrainageBasin mdDrainageBasin = mdDrainageBasinService.findById(id);List list = mdWaterSystemMapper.findByWater(mdDrainageBasin.getBasinCode());if (list.size() > 0) { return ResponseMsgUtil.failure();} else { mdDrainageBasin.setState(1); mdDrainageBasinService.update(mdDrainageBasin); return ResponseMsgUtil.success(mdDrainageBasin);}

Query which watershed is based on the Id passed in from the front end, and how many water systems there are under this watershed. If there are water systems, do not delete them. If there are no water systems, delete them.

mysql recovery logic delete method will first give you to talk about here, for other related issues you want to know can continue to pay attention to our industry information. Our section content captures some industry news and expertise to share with you every day.

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

Database

Wechat

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

12
Report