【发布时间】:2018-10-05 20:08:15
【问题描述】:
@Entity
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Notification {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long notificationId;
private Long businessId;
private String actionBy;
private String date;
private String notification;
public ArrayList<UserNotification> user;
//constructor here
//getters setters here
}
而 UserNotification.java 是
public class UserNotification {
private Long id;
private String user;
private String notifCount;
//getters setters here
}
我不知道为什么它返回 null。我在什么时候犯了错误?
编辑:
var usersObj=[];
BusinessRoleService.getByBusinessId($sessionStorage.businessRole.business).then(function(response){
if(response.status==200){
for(var x=0;x<response.data.length;x++){
usersObj.push({id: x, user: response.data[x].userId, notifCount: $scope.notification});
}
}
});
var obj = {
"businessId": businessId,
"actionBy": user,
"date": date,
"notification": user+" "+action,
"user": usersObj
}
然后我会将 obj 传递给我的服务进行保存
这是我的数据库保存后的样子
【问题讨论】:
-
你的数组名是
user,但应该是users,看看这个answer -
在您的 IndexController 中将列表名称用户更改为用户
-
Javascript 和 java 对象名都应该匹配
-
请再次查看帖子。它现在保存但为空
-
更新您的问题并提供完整的 Notification 和 UserNotification 类定义(带有每个注释)
标签: javascript java angularjs pojo