欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

form表单,转Map,转List

程序员文章站 2024-02-15 19:13:17
...

1、form表单包含,select下拉列表,input输入框等,转为Map,js如下:

            var baseInfo = {};
        	var formArray =$("#baseInfo").serializeArray();
        	$.each(formArray,function(i,item){
        		baseInfo[item.name] = item.value;
        	});

注:$("#baseInfo"),baseInfo是form的id

 

2、form表单包含,select下拉列表,input输入框等,转为List<Map>,js如下:

			var workInfoArr=[];
			$("#workContent form").each(function(){
				var formObject01 = {};
				var formArray01 =$(this).serializeArray()
	        	$.each(formArray01,function(i,item){
	        		formObject01[item.name] = item.value;
	        	});
				workInfoArr.push(formObject01);
			})

注:$("#workContent form"),workContent form,workContent 是div的id

 

3、ajax的调用,传递的参数如下:

            var jg={"baseInfo":baseInfo,"workInfoArr":workInfoArr}
        	$.ajax({
                type: "post",
                url:"${pageContext.request.contextPath}/refordInfo/updateRefordInfo",
	        async: true,
	        data: JSON.stringify(jg),
	        contentType : 'application/json',
	        dataType:"json",
	        success: function(data) {
                    alert("提交成功")
                },
                error: function(request) {
                    alert("提交失败")
                }
              
            });

4、后端使用@RequestBody Map<String,Object> map接收参数