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
Communication between containers 1. Network shari...
** Install mysql-8.0.20 under Linux ** Environmen...
mysql master-slave configuration 1. Preparation H...
Often, after a web design is completed, the desig...
introduction The company's recent Vue front-e...
Basic Concepts Absolute positioning: An element b...
Table of contents Preface Step 1: Setup and front...
This article uses examples to illustrate the opti...
If you want to become a Linux master, then master...
Download: http://dev.mysql.com/downloads/mysql/ U...
grammar: background-image: conic-gradient(from an...
Solution to Host 'xxxx' is not allowed to...
The scroll bar position is retained when scrollin...
This article describes how to install Apache on a...
Table of contents forEach() (ES6) method map() (E...