1、新建json文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[
  {
    "id": 1,
    "name": "酒水专区",
    "imageUrl": "7cf/e61b0aec87f07393.png",
    "previewImageUrl": "/9f8d4360d3a125b5.png"
  },
  {
    "id": 2,
    "name": "日用百货专区",
    "imageUrl": "9221223/8b2783f4a7ebe1af.png",
    "previewImageUrl": "/7599ca45/9c3720437ea72574.png"
  },
  {
    "id": 3,
    "name": "美食特产专区",
    "imageUrl": "E17ac2dcf/24a370adaae23b59.png",
    "previewImageUrl": "8fc18e575458ae3.jpg"
  }
]

2、读取json文件,并转换为对象

1
2
3
4
5
6
7
8
9
10
11
List<ShopTemplate> list;
      try {
          File file = ResourceUtils.getFile("classpath:template.json");
          String json = FileUtils.readFileToString(file, "UTF-8");
 
          list = JSON.parseObject(json, new TypeReference<List<ShopTemplate>>() {});
 
      } catch (Exception e) {
          throw new RuntimeException(e);
      }
      return list;