在Spring ajax调用上有400个错误请求

时间:2013-08-02 09:55:11

标签: java ajax json spring spring-mvc

我在spring ajax调用中遇到错误。我知道这是一些语法错误,但无法找到它是什么。有人可以帮忙吗?

脚本:

$.ajax({
        type : 'POST',
        contentType : 'application/json; charset=utf-8',
        url: 'saveCommittedAmount.html?investmentId='+investmentId+ '&=transactionData' +transactionData + '&=investorId' +investorId + '&committedAmt='+committedAmt,
        success: function(response) {
            return false;
        }
    });

Spring Controller:

@RequestMapping(value = "/saveCommittedAmount", method = RequestMethod.POST)
    @ResponseBody
    public String saveInvestmentValue(@RequestParam("investmentId") String investmentId,
            @RequestParam("transactionDate") String transactionDate,@RequestParam("investorId") String investorId,
            @RequestParam("committedAmt") String committedAmt) throws ParseException {
        Transaction transaction = new Transaction();

        Date tDate = (Date) new SimpleDateFormat("MM/dd/yyyy").parse(transactionDate.trim());

        transaction.setCommittedAmount(BigDecimal.valueOf(Double.valueOf(committedAmt)));
        transaction.setUserId(Integer.parseInt(investorId));
        System.out.println("committedAmt" + "committedAmt");
        transaction.setTransActDate(tDate);
        transaction.setInvestmentId(Integer.parseInt(investmentId));
        assetService.updateTransaction(transaction);
        return Constants.RESPONSE_SUCCESS;
    }

1 个答案:

答案 0 :(得分:2)

您的saveInvestmentValue方法需要@RequestParam("transactionDate")

但是,您的ajax调用会发送transactionData。您应该将其更改为相同

 url: 'saveCommittedAmount.html?investmentId='+investmentId+ '&=transactionDate' +transactionDate + '&=investorId' +investorId + '&committedAmt='+committedAmt,