zwh0910

前端传递数据:

handleSubmit() {this.dialogVisible = false;
        const param = { \'bidSampleImgList\': this.fileList, \'id\': this.keyId };
        this.update(param)
      },

前端传递字符串到后台,后台通过JSONObject进行接收,注意不是JsonObject.

将字符串数组转换成List集合分两步

通过JSONObject的getJSONArray方法将字符串数组转换成JSONArray,再用JSONArray的toJavaList方法的将JSONArray转换成List集合

注意:将JSONArray转化成List集合时,toJavaList方法的参数是实体类的class类型,而不是List<AttachFile>

@PostMapping(value = "edit")
    public Result editIn(@RequestBody JSONObject jsonObject){
        int id = jsonObject.getIntValue("id");
        JSONArray jsonArray = jsonObject.getJSONArray("bidSampleImgList");
        List<AttachFile> attachFiles = jsonArray.toJavaList(AttachFile.class);
        In in = new In();
        in.setBidSampleImgList(attachFiles);
        in.setId(id);
        return inService.editIn(in);
    }

 总结:如果前端要传递一个List到后台,将List放在JSON中传递,后台用JSONObject接收,这是基本的思路

分类:

技术点:

相关文章:

  • 2021-12-27
  • 2021-10-09
  • 2021-11-20
  • 2021-12-21
  • 2022-02-05
  • 2021-09-28
  • 2021-11-05
  • 2021-10-26
猜你喜欢
  • 2021-11-18
  • 2021-12-27
  • 2021-12-27
  • 2021-07-16
  • 2021-12-27
  • 2021-11-07
相关资源
相似解决方案