How to set a field as null in Mybatis Plus?

In MyBatis-Plus, you can use the @TableField annotation to designate a field as nullable.

  1. Field in the table
  2. implement a plan
  3. strategy update
  4. Null field strategy
@TableField(insertStrategy = FieldStrategy.NULL, updateStrategy = FieldStrategy.NULL)
private String fieldName;

In this way, the value of the field will be set to null when inserting and updating data.

  1. Field in the table
  2. implementing a strategy
  3. modify the plan
  4. No strategy in the field.
@TableField(insertStrategy = FieldStrategy.NULL, updateStrategy = FieldStrategy.NULL)
public class MyEntity {
    // ...
}

In this way, when inserting and updating data, all field values will be set to null.

Please note: The above method is applicable for configuring entity class fields using annotations. If configuring entity class fields using XML, you will need to manually set the fields to null in the XML file.

bannerAds