[Solutions] <Serialization> 返给前端对象 属性为null 不显示(配置BUG)

当使用Spring Boot和Lombok时,若配置了只序列化非null属性,会导致数据库查询结果中为null的属性在返给前端时不显示。解决方法包括在DTO类上添加@JsonInclude(value=JsonInclude.Include.ALWAYS)注解,或者检查并修改application.yml中的jackson配置,确保默认包含null属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

现象

DTO对象:

        CompanyBasicInfoReq.class

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CompanyBasicInfoReq {
    @ApiModelProperty("公司表主键")
    private Long id;

    @ApiModelProperty("公司名称(中文)")
    private String companyNameZh;

    @ApiModelProperty("注册金额")
    private BigDecimal registeredAmount;

    @ApiModelProperty("公司成立日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date establishmentDate;        

    @ApiModelProperty("公司实际办公地址")
    private String actualOfficeAddress;

    //其他字段...
}

         CompanyBasicInfoRes.class

@Data
@Builder
@AllArgsConstructor
@ApiModel(value = "CompanyBasicInfoRes", description = "公司基本信息")
public class CompanyBasicInfoRes {
    @ApiMod
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值