I just learned mybatis today and did some simple additions, deletions, modifications and queries on the database. When performing a deletion operation, it is very simple to delete a single record, but it is a bit troublesome to splice the deletion conditions when deleting in batches. The following is a record of the method. In SQL statements, when the deletion condition is not unique, we have two types of deletion SQL statements. One is to use or to concatenate the conditions in where, such as delete from table name where condition 1 or condition 2, and the other is to use in, such as delete from table name where element in () Use the first deletion statement to splice in mapping.xml in mybatis: Use the second deletion statement to splice in mapping.xml in mybatis: The above deletion operation is basically completed. However, there is a defect. When there is no element in the query condition idList, the records in the entire table ac01 will be deleted. Therefore, we need to improve the above method. The second delete statement is improved: After the first delete statement is improved: At this point, the deletion operation is completed perfectly. Additional knowledge: Pay attention to the and splicing conditions when querying myBatis <!-- Add a condition--> <sql id="queryjiachaAllPageId"> <where> <if test="danweimc !=null and danweimc !=''"> and jcb.danweimc like '%${danweimc}%' </if> <if test="ge_jianchaks !=null and ge_jianchaks !=''"> and DATE_FORMAT(jcb.jianchaks, '%Y-%m-%d') >= #{ge_jianchaks} </if> <if test="le_jianchaks != null and le_jianchaks != ''"> and DATE_FORMAT(jcb.jianchaks, '%Y-%m-%d') <= #{le_jianchaks} </if> <if test="jiancharxm !=null and jiancharxm !=''"> and jcb.jiancharxm like '%${jiancharxm}%' </if> <if test="zhuangtai !=null and zhuangtai !=''"> and yhb.zhuangtai = ${zhuangtai} </if> <if test="danweilb !=null and danweilb !=''"> and yhb.yinhuanmc like '${danweilb}%' </if> <if test="jiedao != null and jiedao !='' and jiedao !='110105000000'"> and jcb.jiedao=#{jiedao} </if> <if test="danweimcs != null and danweimcs !=''"> and jcb.danweimc = #{danweimcs} </if> </where> </sql> For example, the appeal questions either have "and" or "no" added. Please note that if there is an "and" or "no" query, an error will be reported. The above article on solving the splicing problem of deleting conditions in myBatis is all the content that the editor shares with you. I hope it can give you a reference, and I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Vue implements websocket customer service chat function
>>: HTML form_PowerNode Java Academy
This article describes MySQL index coverage with ...
Preview: Code: Page Sections: <template> &l...
How to determine whether the current Linux system...
IDEA is the most commonly used development tool f...
This article shares the specific code of js to im...
1. Prepare the Docker environment 2. Search for f...
What is VNode There is a VNode class in vue.js, w...
1. Manually create and add my.ini file # CLIENT S...
After solving the form auto-fill problem discussed...
Table of contents Matlab Centroid Algorithm As a ...
Overview of MySQL Partitioned Tables We often enc...
Project scenario: 1. Upload file restrictions Fun...
1. Download address: http://dev.mysql.com/downloa...
Each of these 16 sites is worth reading carefully,...
1. Unzip MySQL 8.0.16 The dada folder and my.ini ...