一、前言
接到一个问题,数据库为Null的数据,传递到前端显示为0。之前有了解过,持久层框架(mybatis)在把数据库数据封装到对象中,是利用对象的Setter方法,这个大家也都知道,因此我就在Setter方法尝试,结果并不完全是这样。下面我用例子演示。
二、准备阶段
1.数据表
2.表对应的实体类
@Data
@ApiModel("用户账号")
public class User {
@ApiModelProperty(value = "用户id")
Integer id;
@ApiModelProperty(value = "密码")
String password;
@ApiModelProperty(value = "用户名")
String name;
@ApiModelProperty(value = "状态")
Integer type;
public void setType(Integer type) {
if (type == null) {
this.type = 0;
} else { <