美文网首页
Object接收数据为LinkedHashMap处理

Object接收数据为LinkedHashMap处理

作者: Geroge1226 | 来源:发表于2021-06-23 14:13 被阅读0次

1、场景

开发过程中遇到前端传入List<Object>集合中数据类型不一致情况,不可用具体的实体类接收,而选择了Object,前端数据结构如下:

{
    "floors":[
        {
            "floorType":"2",
            "id":"1624418913871",
            "multipleImagesType":"1",
            "hasTitle":false,
            "imageGroup":[{
                    "id":"1624418915504",
                    "imageUrl":"https://yyoldossfilehdd.blob.core.chinacloudapi.cn/nextstore-apps-test/52ad54e27237a0fb5d43b2a69668b304.png",
                    "jumpType":"6"
                } ]
        },
        {
            "floorType":"4",
            "id":"1624418927263",
            "isTransparent":true
        },
        {
            "floorType":"3",
            "id":"1624418929621",
            "autoRoll":false,
            "hasTitle":false,
            "imageGroup":[{
                    "id":"1624418932871",
                    "imageUrl":"https://yyoldossfilehdd.blob.core.chinacloudapi.cn/nextstore-apps-test/5b92bcd65c77d9a7929ac729c0331bf7.png",
                    "jumpType":"7"
                }]
        }
    ],
    "pageName":"测试页面",
    "districtId":"MYEXP_DISTRICT_9f1ec9d4db364665acaf356b50325b22",
}

后端在处理使用floors集合的类

 public void insertIndexFloor(List<Object> floors,Integer indexId){
        for(Object object : floors){
            MyexpIndexPageFloor record = new MyexpIndexPageFloor();
            record.setIndexId(indexId);
            record.setFloorDetails(object.toString());
            floorMapper.insertSelective(record);
        }

    }

断点调试发现object类型如下:

image.png

2、解决方式

方式一:转换object
方式二:在接收地方直接使用JSONObject接收

public class IndexFloorAddReqDTO {
    // 省略其他实体内容
    private List<JSONObject> floors;
}

相关文章

网友评论

      本文标题:Object接收数据为LinkedHashMap处理

      本文链接:https://www.haomeiwen.com/subject/tqrbyltx.html