下面是对我的控制器的ajax调用
$('#submitButton').on('click', function() { var expenseDetailsListVO = {}; expenseDetailsListVO = getData(); console.log(expenseDetailsListVO); var data = JSON.stringify(expenseDetailsListVO); console.log(data); $.ajax({ url : "${pageContext.request.contextPath}/saveExpenses", data : data, method : 'POST', contentType : "application/json", success : function(data) { }, error : function(data) { } }); });
这是我的控制器
@RequestMapping (value = "/saveExpenses", method=RequestMethod.POST) public String saveExpenses (@RequestBody(required=false) ExpenseDetailsListVO expenseDetailsListVO, Model model) { //System.out.println("User Id is........ "+userId); System.out.println(expenseDetailsListVO); ExpenseDetailsList expenseDetailsList = MapperUtil.convertExpenseListVOToDO(expenseDetailsListVO); //expenseServiceManagement.addExpense(expenseDetailsList); return "addExpense"; }
以下是我的Java类
public class ExpenseDetailsListVO { private List<ExpenseDetailsVO> expenseDetailsVOs = LazyList.decorate( new ArrayList<ExpenseDetailsVO>(), FactoryUtils.instantiateFactory(ExpenseDetailsVO.class)); public ExpenseDetailsListVO (){} public List<ExpenseDetailsVO> getExpenseDetailsVOs() { return expenseDetailsVOs; } public void setExpenseDetailsVOs(List<ExpenseDetailsVO> expenseDetailsVOs) { this.expenseDetailsVOs = expenseDetailsVOs; } @Override public String toString() { return "ExpenseDetailsListVO [expenseDetailsVOs=" + expenseDetailsVOs + "]"; } } public class ExpenseDetailsVO { /*private int expenseId;*/ private String itemDescription; private double amount; private Date expenseDate; public ExpenseDetailsVO (){} /*public int getExpenseId() { return expenseId; } public void setExpenseId(int expenseId) { this.expenseId = expenseId; }*/ public String getItemDescription() { return itemDescription; } public void setItemDescription(String itemDescription) { this.itemDescription = itemDescription; } public double getAmount() { return amount; } public void setAmount(double amount) { this.amount = amount; } public Date getExpenseDate() { return expenseDate; } public void setExpenseDate(Date expenseDate) { this.expenseDate = expenseDate; } @Override public String toString() { return "ExpenseDetailsVO [itemDescription=" + itemDescription + ", amount=" + amount + ", expenseDate=" + expenseDate + "]"; } }
以前它可以正常工作,但是我进行了一些更改,使我不记得了,现在由于客户端发送的请求在语法上不正确,导致浏览器控制台出现错误
伙计们,请让我知道这是什么问题…
有一个很小的错误,因为它显示了该错误…所以我只需要做一些小改变,下面是jQuery
我的控制器希望有一个对象,该对象将具有对象数组,但从客户端它正在发送数组,因此该数组需要包装在我做过的一个对象中并起作用:)