Mybatis-plus update policy part fields are not updated
Directly upload the code
@Documented @Retention() @Target({, ElementType.ANNOTATION_TYPE}) public @interface TableField { String value() default ""; boolean exist() default true; String condition() default ""; String update() default ""; FieldStrategy insertStrategy() default ; //Add new FieldStrategy updateStrategy() default ; //Revise FieldStrategy whereStrategy() default ; FieldFill fill() default ; boolean select() default true; boolean keepGlobalFormat() default false; JdbcType jdbcType() default ; Class<? extends TypeHandler> typeHandler() default ; String numericScale() default ""; }
Five strategies
public enum FieldStrategy { IGNORED, //neglect NOT_NULL, //The field is not null NOT_EMPTY, //The field is not "" DEFAULT, //default NEVER; //Never update private FieldStrategy() { } }
How to use
@TableField(value = "create_user_id", updateStrategy = ) private int createUserId;//Create a userID
The above code means that the field is never updated when modified.
mybatis-plus field update strategy FieldStrategy
public enum FieldStrategy { // Regardless of whether there are or not, all fields will be set to the insert statement. If the value is not set, it will be updated to null. IGNORED, // It is also the default policy, that is, ignoring null fields, not ignoring "" NOT_NULL, // Is null, and the empty string is ignored, that is, if the value is set to null, "", it will not be inserted into the database NOT_EMPTY, // Same as NOT_NULL DEFAULT, // Once inserted, it will never be updated (etc:createTime) NEVER; private FieldStrategy() { } }
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.