In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "mybatis uses foreach to find out how to solve the problem without reporting errors." In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
foreach query does not produce results and does not report wrong questions
First of all, there is no syntax error when executing. Secondly, sql statement can find data when it is taken to the database for execution, but empty input data is returned on the interface side. Check the console and find that sql statement is executed, but the return result is 0. The assumption is that it is a problem with incoming parameters.
execution result
In this case, the array is directly received from the parameter
If you look closely at the array at this time, there is still a difference between the ordinary array and the ordinary array.
However, there is no problem in the execution at this time, but no data can be found.
Correct execution of results
array at this time.
ergodic output
So, you can see that it's a parameter problem.
correct way
Since the received array is a json array, it cannot be used directly. It can be converted to an ordinary array.
Parameters passed in from the front end (array is enough)
Use foreach, in operation attention points
Mybatis syntax is not familiar, in writing foreach operation, causing in () error, this situation does not conform to SQL syntax, resulting in program error.
If you simply make a non-empty judgment, there may also be problems: originally in an empty list, there should be no data, but it becomes all the data!
Error sql example select count(1) from ( SELECT distinct a.* FROM active AS a LEFT JOIN active_promotion AS ap ON ap.active_id = a.id LEFT JOIN promotion_product AS pp ON pp.promotion_id = ap.promotion_id LEFT JOIN active_area AS aa ON aa.active_id = a.id and aa.status = 1 and aa.area_type = 0 WHERE a.status 0 AND a.id = #{id} AND a.name LIKE CONCAT('%',#{name},'%') AND pp.sku = #{sku} and aa.area_id IN #{item} order by a.create_time desc ) as b The corrected SQL is select count(1) from ( SELECT distinct a.* FROM active AS a LEFT JOIN active_promotion AS ap ON ap.active_id = a.id LEFT JOIN promotion_product AS pp ON pp.promotion_id = ap.promotion_id LEFT JOIN active_area AS aa ON aa.active_id = a.id and aa.status = 1 and aa.area_type = 0 WHERE a.status 0 AND a.id = #{id} AND a.name LIKE CONCAT('%',#{name},'%') AND pp.sku = #{sku} and aa.area_id IN #{item} and 1=0 order by a.create_time desc ) as b "mybatis uses foreach to find out how to solve the problem that does not give results and does not report errors" is introduced here. Thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
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.