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

Angular向Spring Boot传递Map<String,String>[]接收为空的问题排查

Angular向Spring Boot传递Map数组后端接收为空的问题

我在开发Angular Web应用时,尝试向Spring Boot REST API发送List<Map<String, String>>类型的数据,但后端序列化后得到的是空列表。之后我又尝试改用Map<String, String>[]数组以及对象类型的Map,问题依然存在。

相关代码定义

后端POJO定义

public class ClasseurDTO {

    private Map<String,String>[] ongletGeneralite;
    
    public ClasseurDTO() {
    }

    public Map<String, String>[] getOngletGeneralite() {
        return ongletGeneralite;
    }

    public void setOngletGeneralite(Map<String, String>[] ongletGeneralite) {
        this.ongletGeneralite = ongletGeneralite;
    }
    
    @Override
    public String toString() {
        // parse ongletGeneralite object 
        String str = "";
        for (Map<String, String> map : ongletGeneralite) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                str += entry.getKey() + " : " + entry.getValue() + " ,";
            }
        }

        return "ClasseurDTO [ongletGeneralite=" + str + "]";
    }
}

前端TypeScript类型定义

export type ClasseurDTO = {
     ongletGeneralite : Map<string, string>[]
}

后端API方法

@PostMapping("/public/observations/import-observations")
public ResponseEntity<String> importObservations(@RequestBody ClasseurDTO classeur) {
    observationService.importObservations(classeur);
    return ResponseEntity.ok().body("Importation terminée");
}

前端HTTP调用代码

importClasseur(classeur: ClasseurDTO): Observable<HttpResponse<{}>> {
    console.log("importClasseur" , classeur)
    return this.http
    .post(`${this.resourceUrlPublic}/import-observations`, classeur, { observe: 'response' });
}

数据确认信息

  • 调用API前的客户端日志:打印出的classeur对象中,ongletGeneralite是包含多个键值对Map的数组,数据完整有效
  • 网络调试工具中的请求Payload:实际发送的请求体里,ongletGeneralite字段为空数组

恳请各位帮忙定位问题所在?

内容的提问来源于stack exchange,提问作者Manolo de la Vega

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 21:12:56