In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Most people don't understand the knowledge points of this article "mybatis mapper.xml annotation pit with parameters", so Xiaobian summarizes the following contents for everyone, the contents are detailed, the steps are clear, and it has certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "mybatis mapper.xml annotation pit with parameters".
mybatis mapper.xml comments pit with parameters
Recently, I did a very simple statistical project. The statistical logic product has been revised. In order to facilitate the quick switch back to the old version of the logic when the product returns later, I commented on the previous sql directly below and wrote a new sql. When commenting, I usually select Ctrl+/after using the editor's own automatic comment function. At this time, the editor is divided into two situations: Case 1 is that your old sql does not have such a statement with special angle brackets. At this time, if you use Ctrl+/, the editor will annotate your old sql with '--', that is, the comment of sql statement. After commenting, the editor will not report an error. If you are lucky that there are no parameters in your previous statement, there will be no problem in execution. However, pay attention to this. However, if your previous sql statement has parameters such as #{xxxx} or ${xxx},
It looks like this:
-- #{month,jdbcType=VARCHAR}
Congratulations, if you execute it at this time, you will report a very strange exception, similar to the following:
org.springframework.dao.TransientDataAccessResourceException:
### Error querying database. Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
This time you may be as confused as I am, especially if you have not encountered this problem before, it is likely to be here for a long time; the second case is that your old sql has such a statement with angle brackets, this time you use Ctrl+/, it will automatically be the standard xml comment, this time even if you comment xxx includes external parameter placeholders, execution will not report errors, such as the following will not have problems:
This problem has not been encountered before, so this time it took a long time to try out the cause of the problem. As for why the two ways are different, I have to look back at the source code of mybatis, and then add it to this article. Take up working time to make a record.
Comments in mybatis xml need to be careful to report errors
java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2)
Debugging for a long time, online check for a long time is #,$usage errors, a comparison, a word to find, found that usage is no problem, suddenly... See the comments in
#{executorId}, think about it, maybe that's the reason? Then he deleted the comment, and found that it was the pot of comments:
So mybatis still counts #{} as an injected parameter, and SQL recognizes the--comment
-- AND (dept.id = #{executorId} OR dept.parentId = #{executorId} OR parentId in ( SELECT id from user_department-- WHERE user_department.id = #{executorId} OR user_department.parentId = #{executorId} ))
The above is about the content of this article "mybatisMapper.xml comments how to solve the pit with parameters". I believe everyone has a certain understanding. I hope the content shared by Xiaobian will help everyone. If you want to know more relevant 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.