向服务器端发布调用时面临问题
异常堆栈跟踪:
"org.springframework.web.bind.MissingServletRequestParameterException: Required int parameter 'answerId' is not present\r\n\tat org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.raiseMissingParameterException(AnnotationMethodHandlerAdapter.java:773)\r\n\tat org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveRequestParam(HandlerMethodInvoker.java:509)
Javascript 调用controller.js
$scope.saveCorrectAnswer = function(answerId) {
var answerIdVal = 0;
answerIdVal = answerId;
if(document.getElementById(answerId).className == 'ico-white-check') {
$scope.answer.correct = 'Y';
} else{
$scope.answer.correct = 'N';
}
Answer.update({answerId: answerIdVal, correct: $scope.answer.correct}, function(response) {
// On success go to Exchange
//$route.reload();
},
java中服务控制器中的映射:
@RequestMapping(method = RequestMethod.PUT, consumes = "application/json", produces = "application/json")
@ResponseBody
public void addCorrectAnswer(@RequestParam int answerId, @RequestParam String correct) {
getAnswerDAC().addCorrectAnswer(answerId, correct);
}