我已经在Google上进行了检查,但无法找出问题所在,而且我是Spring和JSON的新手。
以下是JS和JSON的代码:
function SubmitData() {
var transferReceivedData = {};
var completeList = {};
var totalnumberRecords = document.getElementById('numberOfRecords').value;
for (j = 1; j <= totalnumberRecords; j++) {
var transferIdMain = document.getElementById('transferIdHidden' + j).value;
var subDetailsRowCount = $('#subTable' + j + ' tr').length;
var subRowsData = {};
if (subDetailsRowCount != 1 && subDetailsRowCount != 0) {
subDetailsRowCount = subDetailsRowCount - 1;
for (i = 0; i < subDetailsRowCount; i++) {
var articledesc = document
.getElementById('articleDescHidden' + transferIdMain).value;
var shpQty = document.getElementById('shpQtyHidden'
+ transferIdMain).value;
var remarks = document.getElementById('remarks'
+ transferIdMain).value;
var transferId = document.getElementById('transferId'
+ transferIdMain).value;
subRowsData = {transferId:transferId,
articleDesc:articledesc,
shpQty:shpQty,
remarks:remarks};
}
}
completeList = {
transferId:transferIdMain,
childList:subRowsData
};
transferReceivedData = {
completeList : completeList
};
}
var requestLength = transferReceivedData.length;
console.log("completeList", completeList);
console.log("transferReceivedData", transferReceivedData);
alert("requestLength.... "+requestLength);
if (requestLength != 0) {
$.ajax({
type: "POST",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
url: "${pageContext.request.contextPath}/Pda/saveGoods",
data: JSON.stringify(transferReceivedData),
success: function (response) {
}
});
}
}
以下是Spring控制器的代码:-
@RequestMapping(value = {
"/saveGoods" }, method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public String saveGoods(ModelMap model, HttpSession session, @ModelAttribute PDATransferDataAll transferReceivedData) {
Employee user = (Employee) session.getAttribute("currentUser");
int res = 0;
if (transferReceivedData != null) {
res = 0; //pdaService.saveGoods(completeList, user);
}
if (res != 0) {
model.addAttribute("msg", "Data saved successfully.");
model.addAttribute("id", res);
} else {
model.addAttribute("msg", "Data Not saved ");
}
return "result";
}
以下是豆类:-
public class PDATransferDataAll implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private PDATransferData completeList;
/**
*
*/
public PDATransferDataAll() {
super();
// TODO Auto-generated constructor stub
}
/**
* @return the completeList
*/
public PDATransferData getCompleteList() {
return completeList;
}
/**
* @param completeList
* the completeList to set
*/
public void setCompleteList(PDATransferData completeList) {
this.completeList = completeList;
}
public class PDATransferData implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String transferId;
private List<PDATransferReceivedPojo> childList;
/**
* @return the transferId
*/
public String getTransferId() {
return transferId;
}
/**
* @param transferId
* the transferId to set
*/
public void setTransferId(String transferId) {
this.transferId = transferId;
}
/**
* @return the childList
*/
public List<PDATransferReceivedPojo> getChildList() {
return childList;
}
/**
* @param childList
* the childList to set
*/
public void setChildList(List<PDATransferReceivedPojo> childList) {
this.childList = childList;
}
public class PDATransferReceivedPojo implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String transferId;
private String articleDesc;
private String articleTechDesc;
private String shpQty;
private String receivedQty;
private String status;
private String orderType;
private String remarks;
/**
* @return the transferId
*/
public String getTransferId() {
return transferId;
}
/**
* @param transferId
* the transferId to set
*/
public void setTransferId(String transferId) {
this.transferId = transferId;
}
/**
* @return the articleDesc
*/
public String getArticleDesc() {
return articleDesc;
}
/**
* @param articleDesc
* the articleDesc to set
*/
public void setArticleDesc(String articleDesc) {
this.articleDesc = articleDesc;
}
/**
* @return the shpQty
*/
public String getShpQty() {
return shpQty;
}
/**
* @param shpQty
* the shpQty to set
*/
public void setShpQty(String shpQty) {
this.shpQty = shpQty;
}
/**
* @return the receivedQty
*/
public String getReceivedQty() {
return receivedQty;
}
/**
* @param receivedQty
* the receivedQty to set
*/
public void setReceivedQty(String receivedQty) {
this.receivedQty = receivedQty;
}
/**
* @return the status
*/
public String getStatus() {
return status;
}
/**
* @param status
* the status to set
*/
public void setStatus(String status) {
this.status = status;
}
/**
* @return the orderType
*/
public String getOrderType() {
return orderType;
}
/**
* @param orderType
* the orderType to set
*/
public void setOrderType(String orderType) {
this.orderType = orderType;
}
/**
* @return the remarks
*/
public String getRemarks() {
if (remarks == null || remarks.equalsIgnoreCase("null")) {
remarks = "";
}
return remarks;
}
/**
* @param remarks
* the remarks to set
*/
public void setRemarks(String remarks) {
if (remarks == null || remarks.equalsIgnoreCase("null")) {
remarks = "";
}
this.remarks = remarks;
}
/**
* @return the articleTechDesc
*/
public String getArticleTechDesc() {
return articleTechDesc;
}
/**
* @param articleTechDesc
* the articleTechDesc to set
*/
public void setArticleTechDesc(String articleTechDesc) {
this.articleTechDesc = articleTechDesc;
}