第一种方案 @JsonIgnore
返回和接收都不需要密码
@Data
public class User {
@Id
private int id;
@Column(name = "name")
private String userName;
@JsonIgnore
@Column(name = "password")
private String userPassword;
}
第二种方案 @JsonIgnoreProperties(value = "userPassword", allowSetters = true)
可以接收密码,不返回密码
@Data
@JsonIgnoreProperties(value = "userPassword", allowSetters = true)
public class User {
@Id
private int id;
@Column(name = "name")
private String userName;
@Column(name = "password")
private String userPassword;
}
注意!!! JsonIgnoreProperties里面的value使用class 字段,不是mysql的列名