【问题标题】:Passing an array from Spring Boot to Reactjs via postmapping only returns the first object通过后映射将数组从 Spring Boot 传递给 Reactjs 仅返回第一个对象
【发布时间】:2021-10-27 11:42:34
【问题描述】:

我正在使用 Spring Boot Server 开发 reactjs。 当通过 axios 从 reactjs 进行映射后调用以检索对象列表时,不知何故,我只能获取第一个对象,而其他对象仅显示 id。代码如下:

反应端

    checkAllOffer(){
        axios.post("http://localhost:8080/post/getAllOffer/"+ this.state.id)
        .then(response => {
            console.log(response.data);
        })

    }

Spring Boot 端

控制器方法

    @PostMapping("/post/getAllOffer/{id}")
    public List<Offer> checkOwnOffer(@PathVariable("id") int postId)
    {

        CarPosting currentPost = cpservice.findCarPostById(postId);
        List<Offer>allCurrentOfferForCurrentPost =  currentPost.getOffers();
        return allCurrentOfferForCurrentPost;
        

    }

spring boot 打印数据很好

但在控制台端,记录详细信息显示对象 2 缺少信息

【问题讨论】:

  • JSON.stringify(response.data) 的输出是什么?
  • 什么也没有出现。甚至不是数组中的第一个对象

标签: java reactjs spring-boot


【解决方案1】:

我设法通过从商品实体类中删除 @JsonIdentityInfo 来解决它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-12
    • 2019-07-06
    • 2016-02-16
    • 2015-10-23
    • 2018-11-03
    • 2013-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多