In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to solve the problem that mybatis if test is not an empty string and is not null". In daily operation, I believe many people have doubts about how to solve the problem that mybatis if test is not an empty string and is not null. The editor consulted all kinds of materials and sorted out a simple and useful method of operation. I hope it will be helpful for you to answer the problem that mybatis if test is not an empty string and is not null. Next, please follow the editor to study!
If test is not an empty string and is not null if test in mybatis
When judging that it is not an empty string and null, a sql syntax error is reported
Xml file:
WHERE enable = 1 AND (mac_id = # {keyword}) OR (user_id = # {keyword})
The error in the postman tool is as follows:
Reason:
A case error occurred in if judgment, which does not conform to the mybatis grammar specification.
In mybatis, if test syntax
1 judge that it is not null
WHERE 1 # 1 AND user_id = # {keyword}
2 determine that it is not an empty string
WHERE 1 # 1 AND user_id = # {keyword}
3 determine that it is not a null and is not an empty string
WHERE 1 AND user_id = # {keyword} Controller layer-> corresponding xml file
When we get the list, we usually make an accurate or fuzzy query according to the keywords, and then make a non-empty or non-null judgment on the keywords. As follows:
Controller layer request parameters keyword request parameters default value Dao layer Xml file @ RequestParam (value = "keyword", required = false) String keywordnullif test= "keyword! = null" @ RequestParam (value = "keyword", required = false DefaultValue = "") String keyword empty string if test= "keyword! =''" / unclear default value can be if test= "keyword! = null and keyword! =''" Parameter default value Dao layer Xml file data obtained from other sources or keywords unclear default value if test= "keyword! = null and keyword! =''" mybatis treats 0 as an empty string
In development, it is common to judge whether the parameter is null or an empty string in sqlmap.
When the parameter is Int type 0, myBatis automatically defines 0 as an empty string ""
We add one more judgment where the input parameter is 0, a.AUTHORIZE_AMOUNT = # {authorizeAmount,jdbcType=VARCHAR} so far, the study on "how to solve the problem that mybatis if test is not an empty string and is not null" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.