In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you how to solve the problem that mybatis can not assign values to underlined attributes, the content is simple and clear, and I hope it can help you solve your doubts. Let me take you to study and learn "how to solve the problem that mybatis cannot assign values to underlined attributes".
Mybatis cannot assign a value to an underlined attribute. 1. Configuration question
Or
/ / enable hump mapping bean.getObject (). GetConfiguration (). SetMapUnderscoreToCamelCase (true)
After this is set in the mybatis configuration file, if the queried field is underlined, then the underscore will be removed and the java hump rule will be adopted. For example, if the database field Parent_id is queried, it will be changed to parentid, and then go to the entity class to match the corresponding field. Because there is an underscore in your entity class, it doesn't match. Either use resultMap or disable the hump rule (not recommended). If you do not want to change the entity class, it is recommended to use resultMap.
2. Increase the way the set method converts values.
Original entity class
Public class demo {private String user_name; private Striing pass_word; public String getPass_word () {return pass_word;} public void setPass_word (String pass_word) {this.pass_word=pass_word;}}
Original sql
Select user_name,pass_word from demo
This sentence sql can be found in the database, but not in entity class queries using mybatis.
Solution method
Add the following two set methods to the entity class and change sql to
Select user_name as username,pass_word as password from demo
Querying a database with an entity class is actually a set process that requires only one set method for each attribute.
Public void setUsernaem (String user_name) {this.user_name=user_name;} public void setPassword (String pass_word) {this.pass_word=pass_word;}
It is only applicable to situations where it is not convenient to change entity classes.
There is a problem that the sliding line field cannot be assigned in the entity class.
There is a drop line field in the entity class, and mybatis cannot assign a value.
Remove the underscore from the entity class directly
The return value uses resultMap for field mapping assignment
The above is about "how to solve the problem that mybatis cannot assign values to underlined attributes". If this article is helpful to you and you think it is well written, please share it with your friends to learn new knowledge. if you want to know more about it, please pay more 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.