Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of foreach nested if tags in mybatis

Shulou Source: shulou.com Published: 2022-06-01 04:07:33 09月22日 Update

Editor to share with you the example analysis of foreach nested if tags in mybatis. I hope you will get something after reading this article. Let's discuss it together.

Mybatis foreach nested if tags

Code implementation:

Mapper.java file

List getYsxmcodeByYszbh (@ Param ("qyName") List qyName, @ Param ("yszh") String yszh)

XXX.xml file

Union select ysxmcode from ${qy} _ yxsxk.tpc_ysxkz where yszbh=# {yszh,jdbcType=VARCHAR}

To judge whether it is the first loop, do not add union splicing, otherwise add

The difference between xml files $and #

${} will be directly replaced by variables when precompiled, but there is a problem of being injected, the table name must be ${}, because # {} will be resolved to? Placeholder, but when replaced by a variable, single quotation marks are added to indicate that single quotation marks are not allowed (but backquotation marks ``are OK)

The difference between union and union all

1.union all is a direct connection, taking all the values, the record may be duplicated; union is the only value, the record is not duplicated. So union will filter out duplicate records after table linking, and union all will not remove duplicate records.

2.union will sort by the order of the fields; union all will simply merge the two results and return. Union all is much faster than union in terms of efficiency, so use union all if you can confirm that the two merged result sets do not contain duplicate data and do not need to be sorted.

The nesting of mybatis if and foreach (an indefinite number of query conditions with the same column) has such a requirement

Set different number of query conditions according to the number of entries (set an indefinite number of query conditions on a column), then you need a root.

According to the foreach loop, the query conditions are spliced on a column.

The template is shown below.

After reading this article, I believe you have some understanding of "sample Analysis of foreach nested if tags in mybatis". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Number condition query tag quotation mark file time example analysis two variable article result loop sort different code content just field Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB Linux NVidia vpn