In daily development, the process of doing the update operation is: When the field has a value is updated, no value is not updated, in the MyBatis XML is represented as:
<!--Modify a record to modify only fields that are not empty - <UpdateID= "Updatebyselective"ParameterType= "Object" >Update Tb_mj_user Set<TrimSuffixoverrides="," > <offTest= "sort!= null" >Sort=#{sort},</if> <ifTest= "Updateby! = null" >Update_by=#{updateby},</if> <ifTest= "Updatedate! = null" >Update_date=#{updatedate},</if> <ifTest= "Delflag! = null" >Del_flag = #{delflag},</if> </Trim>WHERE id = #{id}</Update>
When the sort field is of type int, we do the update even if we do not set a value for sort, and the sort is updated to 0 when we finish the updatebyselective operation.
The reason for this is that int is one of the original data types in Java that provides 8, and the default value is 0, which cannot be expressed without assigning a value. At this point, we can define the sort as an integer type, the default null for integers, the ability to differentiate between unassigned cases, and the limitations of updatebyselective operations, which are updated when not empty.
Java-int type: int defaults to 0 to cause the update operation to update to 0 without assigning a value