You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Data JPA嵌入式实体类如何在Postman中传递请求体?

问题分析与解决方案

问题根源

你的JSON请求体存在两个核心错误,导致defectiveComponentInfo字段始终为null:

  1. 字段名大小写不匹配:实体类中嵌入字段的名称是defectiveComponentInfo(小驼峰命名),但你JSON里写的是DefectiveComponentInfo(首字母大写),Jackson默认属性映射区分大小写,无法识别。
  2. 数据类型不匹配:实体类中defectiveComponentInfo是单个DefectiveComponentInfo对象,而你用数组[]包裹了内部字段,类型不匹配导致反序列化失败。

正确的JSON请求体

{
    "userName": "sam",
    "contactNumber": "96014587555",
    "defectiveComponentInfo": {
        "componentType": "Integral",
        "componentName": "Bummper",
        "quantity": 5,
        "description": "Repair product"
    }
}

扩展场景提示

如果业务需要支持多个缺陷组件信息,需先修改实体类字段类型为集合:

@ElementCollection
private List<DefectiveComponentInfo> defectiveComponentInfoList;

对应的JSON请求体就可以用数组形式:

{
    "userName": "sam",
    "contactNumber": "96014587555",
    "defectiveComponentInfoList": [
        {
            "componentType": "Integral",
            "componentName": "Bummper",
            "quantity": 5,
            "description": "Repair product"
        }
    ]
}

内容的提问来源于stack exchange,提问作者vishwa_001

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 17:57:24