我可以毫无问题地将项目添加到我的grails应用程序中,当我显示它们时,它看起来像这样:
[{"class":"server.Item","id":1,"assignedTo":"a","comments":null,
"completed":false,"creator":"a","name":"l","priority":"2","type":"Work"}]
只是一个JSON对象列表,它工作得很好,它仍然存在于我的客户端等。
但是,当我尝试更新时,我得到一个空指针异常:
2015-05-26 11:56:33,504 [http-bio-8080-exec-10] ERROR errors.GrailsExceptionResolver -
NullPointerException occurred when processing request:
[OPTIONS] /server/todoList/updateList
Cannot set property 'name' on null object. Stacktrace follows:
Message: Cannot set property 'name' on null object
我的更新控制器如下所示:
def updateList() {
def newItem = Item.findById(request.JSON.id)
newItem.name = request.JSON.name
newItem.type = request.JSON.type
newItem.priority = request.JSON.priority
newItem.completed = request.JSON.completed
newItem.comments = request.JSON.comments
newItem.creator = request.JSON.creator
newItem.assignedTo = request.JSON.assignedTo
newItem.save(flush: true)
render newItem as JSON
}
在我的角度控制器中调用它:
$scope.updateList = function() {
angular.forEach($scope.items, function (item) {
// serverList.save({command: 'updateList'}, item);
$http.post('http://localhost:8080/server/todoList/updateList', item)
.success(function(response) {})
.error(function(response) {alert("Failed to update");});
});
};
以下是我的项目的属性:
name: $scope.thing,
type: $scope.worktypeSelection,
priority: $scope.prioritySelection,
completed: false,
comments: '',
creator: $scope.username,
assignedTo: $scope.assign.name