In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you how to solve the problem of how to solve the problem of the value of foreach nested if tag objects in Mybatis. The content is detailed, and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
The value problem of using if tag objects in foreach nesting
Recently, in the course of doing the project, we need to use foreach to read the incoming query conditions in Mybatis, and dynamically splice SQL statements. The query condition format passed by the API is {"advanceSearchList": [{"searchType": 10, "searchText": "12"}]}. According to the parameter format I defined, we need to read the json objects in the advanceSearchList collection dynamically in Mybatis, and do different processing according to the searchType in the json objects. Need to nest if tags in foreach to determine the use.
General format and abc like CONCAT ('%', ddd,'%')
Because the item obtained in the current foreach is a json object, which involves obtaining the value of the specified attribute in the current object in the if tag, it was out of my mind for a moment, and the omnipotent du Niang did not get a satisfactory reply. After a fool-like attempt, she finally found the value method, and hereby records:
Solution.
Mybatis uses the if tag in the foreach tag to get object attributes:
Go directly through the object. The way to get the property! Yes, you read it right, just through the object. The way to get the property!
For example, the object acquired by the current foreach loop is item, and if you want to get the searchType in the object, you can simply item.searchType.
The code is as follows: and abc like CONCAT ('%', # {item.searchText},'%') Mybatis if statement nesting
When using mybatis, you can add the if tag under the if tag.
For example, to improve the sql statement.
Select a.* from emp an inner join dept bon a.deptno = b.nowhere b.place = # {place} requirements
If the location passed in is North Korea, then it is OK to meet the conditions in a.
A.male ='M'or a.age bewteen 20 and 30
The where statement can be written like this
Select * from emp e and (b.place = # {place} or a.male ='M' or a.ge between 20 and 30)
Pay attention to the brackets inside.
These are all the contents of this article entitled "how to solve the problem of using if tag object values in foreach nesting in Mybatis". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.