问题概述
我们在更新某个用户信息时,如果要将该用户信息的某个字段更新为null值,直接设置用户实体的对应属性为null值是不行的,因为MyBatis-Plus默认看到null值就不更新该字段
解决办法
在实体类的对应属性上添加注解@TableField(updateStrategy = FieldStrategy.IGNORED)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| package com.ledao.entity;
import com.baomidou.mybatisplus.annotation.FieldStrategy; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data;
import java.util.Date;
@Data @TableName(value = "t_contact") public class Contact {
@TableId private Integer id;
private String content;
@TableField(updateStrategy = FieldStrategy.IGNORED) private String reply;
private Date time;
@TableField(value = "userId") private Integer userId;
@TableField(value = "userIdReply") private Integer userIdReply; }
|