前端form表单页面:
function save(){
var data = $("#Formid").serialize().split("&");
var obj={};
//将序列化字段转化为对象格式
for(var key in data)
{
console.log(data[key]);
obj[data[key].split("=")[0]] = data[key].split("=")[1];
}
//all in,添加额外数据,拼接对象
var userAddDTO = {}
userAddDTO .userBaseInfo = obj;
userAddDTO .info1 = [];
userAddDTO .info2 = [];
console.log(projectAddDTO);
//拼接后的对象转为json对象
var param = JSON.stringify(projectAddDTO);
$.ajax({
url : "http://localhost:8080/xxx-web/user/add.do",
type : "POST",
contentType:"application/json",
data : param,
success : function(result) {
if (result == "success") {
layer.msg('保存成功');
} else {
}
},
error:function(msg){
}
})
}
后端代码:
controller层:
@RequestMapping(value = "add",method = RequestMethod.POST)
public MVResult add(@RequestBody UserAddDTO userAddDTO) {
System.out.println("userBaseInfo>"+UserAddDTO.getUserBaseInfo());
return null;
}
DTO层:
@Data
public class UserAddDTO {
private UserBaseInfo userBaseInfo;
private List<InfoVO> info1;
private List<InfVO> info2;
}