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

What if mybatis modifies int data and cannot be changed to 0?

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is to share with you what to do if mybatis modifies int data and cannot change it to zero. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Mybatis modified int data cannot be modified to 0

Encounter a very strange problem, modify an int state quantity in the user entity 1.2.3. All can be modified successfully, except when the parameter is 0, the modification is not successful, the console does not report an error, and everything is normal. The project uses the ssm framework. Finally, it was found that the problem was in mybatis's mapper.xml.

The scene is as follows

Modify the value of status. 0 is disabled and 1 is enabled. When the value passed in is 0, the modification fails.

The process is as follows

This is the modified state quantity part of the mybatis update statement. After consulting the data, we know that the problem lies with status=''. If there is this condition, the result is judged to be false when the parameter is 0, then 0 set will not be entered into the database. (after tossing all night without successfully configuring log4j to print the sql statement parsed by mybatis, the sql statement cannot be shown here.) for the specific reason, you have to refer to the source code to find the answer. Because of my limited ability, I will leave it to myself and Daniel in the future.

Solution method

1. Just get rid of status=''.

two。 Rewrite it into

The present situation of null judgment with a mybatis int type value of 0

The judgment of status value is often encountered in project development. Status is usually set to int type, and different conditions are set for query or editing according to different status. Non-null is often set as the judgment condition of if in Mybatis, and it is often written as follows:

Status = # {status}

When executing the query and editing status=0, the query result does not find out the user information of the status=0, and the status of the editing user is not modified successfully, but the background shows that the value is correct (the background printing information is shown below).

Modify user information

{id=22, username=wangzichun, password=*, email=, telephone=45643, roleId=2, status=0} causes of problems

When the status value is 0, Mybatis will be used as the false result in the if condition, that is, the contents of the if will not be executed. Therefore, when status=0, the filter or modify fields and field values set in the if condition are not set successfully, resulting in unsuccessful query and editing of status=0.

Solution method

Set the if condition of status to or write only

Thank you for reading! On "mybatis modified int data can not be modified to 0" this article is shared here, 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, you can share it out for more people to see it!

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