使用formData向后台传递数组对象

1.前端

let formDatas = new FormData();
let sealValues = t.sealValues;
formDatas.append('pdfFile', t.parsePdfFile);
for(let i=0,len=sealValues.length;i<len;i++){
    let locationInfo = sealValues[i];
    formDatas.append('sealLocationInfoList['+i+'].posX',locationInfo.posX);
    formDatas.append('sealLocationInfoList['+i+'].posY',locationInfo.posY);
    formDatas.append('sealLocationInfoList['+i+'].signOnPage',locationInfo.signOnPage);
    formDatas.append('sealLocationInfoList['+i+'].sealId',locationInfo.sealId);
}

2.后端接收

@RequestMapping(path = "/stamp", method = RequestMethod.POST)
   public ResponseEntity<Map<String, Object>> stamp(
        HttpServletRequest req,
        @Param("pdfFile") MultipartFile pdfFile, SealLocationInfoRequest request
    ) {
          //
      }

3.后台映射对象

public class SealLocationInfoRequest implements Serializable {
    private static final long serialVersionUID = 2392716281569231777L;
    private Long contractId;
    private String filePath;
    private List<SealLocationInfo> sealLocationInfoList;
}

public class SealLocationInfo implements Serializable {
    private static final long serialVersionUID = -8706741125508276806L;
    private Integer posType;//定位或关键字
    private float posX;
    private float posY;
    private String signOnPage;
    private Long sealId;
    private String key;
    private float width;
    private Integer signType;//2.骑缝章  1.其他
}

 

posted @ 2023-01-07 16:22  土小狗  阅读(1626)  评论(0编辑  收藏  举报