FormData 传List对象集合到后台

var formData = new FormData();
                var activityId = $("#activityId").val();
                var dynamicParams = $(".dynamic_param");
                $.each(dynamicParams, function (i, n) {
                    var name = $(n).find("label").text();
                    var val = $(n).find("input").val();
                    formData.append("formRecord[" + i +"].fieldName", name);
                    formData.append("formRecord[" + i +"].fieldValue", val);
                });
                formData.append("activityId", activityId);

                $.ajax({
                    type: "post",
                    dataType: "json",
                    data: formData,
                    async: false,//同步提交
                    cache: false,//禁用缓存
                    contentType: false,//formData禁用contentType
                    processData: false,
                    beforeSend: function () {
                        $.modal.loading("正在处理中,请稍后...");
                    },
                    success: function (result) {
                        if (result.code == "0") {
                            $.modal.msgSuccess(result.msg);
                        } else {
                            $.modal.alertError(result.msg);
                        }
                        $.modal.closeLoading();
                    }
                })

后台格式

@Data
public class OrderFormVo {
    private Long activityId;
    private List<FormRecordVo> formRecord;

    @Data
    public static class FormRecordVo {
        private String fieldName;
        private String fieldValue;
    }

}

 

上一篇:求数组的长度 && strlen求长度


下一篇:指针进阶的笔试题