0
我有AngularJS + SpringMVC项目。 通过GET方法它返回实体列表,所以我可以使用它ng-repeat打印对象数据(名称,例如) 但最近我需要使用hashmap(键 - 对象与字段,值 - 字符串)正确处理SpringMVC中的hashmaps + angularjs
这是代码的一部分,即i的角度
用于解释这是如何对象填充字段列表
<input type="text" ng-model="currentItem.taskName" class="form-control">
app.controller('mainController',function ($scope, $http) {
$scope.tasks = [];
$scope.currentItem = {};
$scope.currentView = 'allTasks';
$scope.refresh = function() {
$http({
method:"GET",
url:"/task"
}).then(function (result) {
$scope.tasks = result.data;
});
};
$scope.refresh();
$scope.save = function(){
$http({
method:"PUT",
url:"/task",
data:$scope.currentItem,
headers:{'X-CSRF-TOKEN':$("meta[name='_csrf']").attr("content")}
}).then(function(result) {
for(var i = 0; i < $scope.tasks.length; i++){
if(result.data.id===$scope.tasks[i].id){
$scope.tasks.splice(i, 1);
}
}
$scope.tasks.push(result.data);
});
$scope.cancel();
};
现在我有这个控制器:
@GetMapping
public Map<TaskEntity,String> findAll(){
user = (UserEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return taskService.findFromUser(user.getId());
}
但它似乎没有工作。 角找不到对象的领域,当我使用
ng-repeat="(k,v) in tasks" {{k.name}}
但打印此k
作为对象名称[email protected]
所以我的问题是:如何正确读取HashMap和添加项目到它
杰克逊,所以不,我不认为这是问题。在列表之间它一切都好 – jusinejo