roujennie 2022-04-29 17:57 采纳率: 80.8%
浏览 19
已结题

JAVA返回类型 floor_title里我想要返回的形式是name和image_src在集合里,而不是在数组里,该如何修改?

我现在的代码:


@GetMapping("floordata")
    public Map<String,Object> floordata() {
        Map<String,Object> map = new HashMap<>();
        Object floor_title = floorDataService.floortitle();
        List<FloorData> product_list = floorDataService.floorproduct();
        map.put("floor_title",floor_title);
        map.put("product_list",product_list);
        return map;
    }

返回的json

{
floor_title: [
  {
    name: "时尚女装",
    image_src: "https://api-hmugo-web.itheima.net/pyg/pic_floor01_title.png",
    image_width: null,
    open_type: null,
    navigator_url: null
}
],
product_list: [
  {
    name: "优质服饰",
    image_src: "https://api-hmugo-web.itheima.net/pyg/pic_floor01_1@2x.png",
    image_width: "232",
    open_type: "navigate",
    navigator_url: "/pages/goods_list/goods_list?query=服饰"
  },
  {
    name: "春季热门",
    image_src: "https://api-hmugo-web.itheima.net/pyg/pic_floor01_2@2x.png",
    image_width: "233",
    open_type: "navigate",
    navigator_url: "/pages/goods_list/index?query=热"
  },
]
}

我希望返回的json形式(主要是floor_title里我想要返回的形式是name和image_src在集合里,而不是在数组里,该如何修改?)

{
  floor_title: {
    name: "时尚女装",
    image_src: "https://api-hmugo-web.itheima.net/pyg/pic_floor01_title.png"
},
  product_list: [
  {
    name: "优质服饰",
    image_src: "https://api-hmugo-web.itheima.net/pyg/pic_floor01_1@2x.png",
    image_width: "232",
    open_type: "navigate",
    navigator_url: "/pages/goods_list?query=服饰"
  },
  {
    name: "春季热门",
    image_src: "https://api-hmugo-web.itheima.net/pyg/pic_floor01_2@2x.png",
    image_width: "233",
    open_type: "navigate",
    navigator_url: "/pages/goods_list?query=热"
  }
  ]
},

  • 写回答

1条回答 默认 最新

  • 吕布辕门 后端领域新星创作者 2022-04-29 19:16
    关注

    外面再套一层HashMap

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 5月7日
  • 已采纳回答 4月29日
  • 创建了问题 4月29日