In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how Mybatis judges empty strings". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how Mybatis judges empty strings".
Mybatis determines an empty string
Let's start with the conclusion: if you use it correctly, it won't cause any problems. All kinds of doubts are caused by improper use.
Let's talk about the correct way to use it first.
The general way to judge a void is:
Non-String types can use obj! = null
String type usually needs to add an empty string to judge obj! = null and obj! =''. If the judgment method corresponding to the input parameter type is used correctly, there will be no problem.
But there are a lot of people who are not serious about things, they will use these two inversely, although the report is not wrong, but the logic is not expected. The wrong use example is that the input parameter is a numeric type, such as Long, but use obj! = null and obj! =''when judging the null, which itself is wrong. You will find that when the Long value is 0, obj! =''is established, which leads to completely unexpected results. The processing method of mybatis is that when you find that you are comparing an object of a numeric type with a string, he will convert the string into a numeric type, and when the string is not empty, there is no problem. When the string is empty, mybatis converts the empty string into the number 0, which is what mybatis does. There are no loopholes. The root of the problem lies in the incorrect operation of judging the empty string for non-string types. The final conclusion is that objects of numeric type should not use the empty string judgment expression obj! =''.
There is another digression.
When the two systems interact, the data does not have a type when it is transmitted over the network, and type identification is carried out only when it reaches the end. We usually interact with the front end, and the data are all strings in the process of transmission, that is, there is no null, so the type specified when the backend receives is very important. It should be noted that when the backend defines the String type, there will be no null (unless the front end does not pass this parameter). It will only be an empty string, so you need to pay attention to it when judging.
Mybatis judged as empty attention.
In startBalance java is the BigDecimal type
To write like this, startBalance! = "" returns false, so the object cannot judge! = ""
Ordinary String is OK.
The above is all the content of the article "how Mybatis judges empty strings". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow 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: 297
*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.