In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the "mybatis entity class field can not get the value of how to solve", in the daily operation, I believe that many people in the mybatis entity class field can not get the value of how to solve the problem, editor consulted all kinds of data, sorted out a simple and useful method of operation, hope to answer the "mybatis entity class field can not get the value of how to solve" the doubt is helpful! Next, please follow the editor to study!
Mybatis entity class field case problem field cannot get a value
Due to previous design problems, a field rootpath is needed in the project, so I added such a field to the entity layer.
Then, when I passed the data from the foreground to the background, the rootpath never got a value. After checking and comparing, I found that the capitalization of the P letter in the RootPath after the name of the set and the get method I wrote was caused.
Solution.
Just change the P after the set and get methods to lowercase p
Infer
Mybatis thought rootpath was a word, but I mistakenly thought it was two words, and then capitalized P when writing set and get, so the field could not get the value!
Trample mybatis conversion case problem
Because the MySQL database is not strictly case-sensitive in the Windows environment, we use an underscore "_" between the two words when naming the tables and fields of the database, such as "user_name". However, when we develop the project, in order to comply with the code specification, the attributes in the entity class are named in the hump style. In this way, MyBatis may error get and set methods that do not have this attribute.
Solution method
1. Use resultMap
Map one by one by column value (database field name) and property value (entity class attribute name) in resultMap.
.
two。 Configure MyBatis:
(1) add the following code to the mybatis-config.xml configuration file:
(2) configure in the application.yml file:
# mybatis configuration mybatis: configuration: map-underscore-to-camel-case: true
The map-underscore-to-camel-case can also be written as mapUnderscoreToCamelCase (not attempted), and then the corresponding entity class is directly used in the xml file of MyBatis to receive the data.
.
When mode (1) and mode (2) are configured at the same time, the priority of mode (2) is higher.
3. Customize how to configure the class: add a ConfigurationCustomizer to the container.
@ Configurationpublic class MyBatisConfig {@ Bean public ConfigurationCustomizer configurationCustomizer () {return new ConfigurationCustomizer () {@ Override public void customize (org.apache.ibatis.session.Configuration configuration) {configuration.setMapUnderscoreToCamelCase (true);};}} at this point, the study on "how to solve the problem that the mybatis entity class field cannot get a value" 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: 281
*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.