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 use Mybatis to delete multiple data

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail how to use Mybatis to delete multiple data. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Mybatis deletes multiple data for example: delete sid=1 and sid=2 data in the database

The steps are as follows

1. Create a LIst in the entity class to hold the sid to be deleted

two。 Configure Mapper.xml as follows:

Collection installs the fields to be traversed, item installs the variables obtained, and separator installs the fields separated by multiple values.

If the SQL delete statement is:

DELETE FROM animal WHERE a_sid IN (1 dint 2)

Use the open= "" close= "in the foreach tag to indicate what begins and ends, respectively.

3. Configure execution statements in the interface file

Public int delMor (Animal animal)

4. Configure the Test related statement test:

Mybatis batch deletion of multi-table data service requirements

You need to clear the data with one click to clear all the table data in the library that begins with the "obj_" prefix.

Truncation statements that query tables that begin with the obj_ prefix

Mapper API method:

/ * query all tables at the beginning of obj to delete sql * / List selectAllObjTableRemoveSql ()

Xml:

SELECT CONCAT ('truncate table', TABLE_NAME,';') FROM information_schema.TABLES WHERE table_schema = 'sc-gateway' AND TABLE_NAME LIKE' obj_%'

Where "obj_" is the table name character to be matched.

The result of the query is a List, where each item is a table truncated statement

You only need to execute each statement once later.

Send the entire String directly to execute.

This is the end of the article ${value} on "how to delete multiple data using Mybatis". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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