Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of mybatis Null value insertion processing

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail the example analysis of mybatis null insertion processing. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

It is suitable for those whose input parameter type is object.

After learning how to insert null values in mybatis, let's sum it up now.

Above is my project. Open the test class and insert a null value to try it.

Above is my Mapper file, entity class and test class. The method passes the object type, and line 25 sets the name. Now do not set the name and execute the entity class.

Console error, cannot set parameters for mapping, invalid column type

Solution: set idbcType in the method called in the mapper file. Since my sName is of String type, handle null values and set jdbcType=VARCHAR. Note that the jdbaType is different for different types of settings. Refer to the figure below.

At the end of the setup, execute the test class test again

The execution is successful. Take a look at the database. The null value has been inserted successfully.

Remember, database field name do not set non-empty constraint, set will report sql exception error, important words three times remember, database field name do not set non-empty constraint, set will report sql exception error, important words three times remember, database field name do not set non-empty constraint, set will report sql exception error, important words say three times

That's what happens when you set a non-empty constraint, and the database just deletes the constraint.

This is the end of this article on "sample analysis of mybatis null insertion processing". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report