In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to solve the problem that mybatis query shows that individual fields of entity class are null. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
Mybatis queries data. Individual fields of entity class are null.
Today, the pit encountered while doing a simple query operation has been tossing about for a long time. It is necessary to record the psychological activities of this vegetable chicken.
After debug single-step execution of the discovery query, several fields are not mapped successfully, and they are still null.
And the sql statement printed by the console did get it.
Wondering if the names of the fields in the entity class were inconsistent, the big dog stared at it ten thousand times and didn't find any difference.
I tried to set a breakpoint in the set method and found that the set method was executed, but the input was empty. It's freaking out.
The final discovery.
There is a whole sentence in the configuration file of mybatis.
There are several columns in the queried data that cannot be encapsulated by null. The columns that exist in the sql query do not exist.
Environment: java web project sql tool navicat
problem
The data queried by my colleague's code always has two columns whose data is null, which is found to be correct after checking the encapsulated returnMap and entity classes, and then the Navicat tool uses sql query to find that several of the columns are named Unknown when querying data according to the column.
(self-made presentation)
data
Looking at the table query (it looks like the sentence is correct, but in fact, he made a mistake and could not find the name column)
Then Navicat looks at the design query of the table and the name column seems to be all right.
I dumped the table as a sql file and opened it and found that the single quotation marks of name were wrapped.
Then click name on nativcat and move to the left to find that name is gone.
After deleting the field and rebuilding it, it is found that it can be queried.
Check table 1 on sqlyog to clearly find the pre-space problem.
Looking at the design structure of the table, you will also find that the name column is not displayed.
Because a space is added before the column name is created, it will not be displayed on the navicat, so it is the correct column name, but if you are a sqlyog, you will find these problems.
After reading the above, do you have any further understanding of how to solve the problem that the individual fields of the data display entity class are null when queried by mybatis? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.